SPR*_*1NG 2 javascript node.js nestjs
我在使用 Nestjs HttpModule 时遇到问题
错误:
Nest can't resolve dependencies of the ShopService (PrismaService, ?). Please make sure that the argument HttpService at index [1] is available in the QaModule context.
我的商店模块:
@Module({
imports: [HttpModule],
controllers: [ShopController],
providers: [ShopService, PrismaService],
})
export class ShopModule {}
Run Code Online (Sandbox Code Playgroud)
我的 Qa 模块:
@Module({
controllers: [QaController],
providers: [QaService, PrismaService, ShopService],
})
export class QaModule {}
Run Code Online (Sandbox Code Playgroud)
解决办法有哪些?
将您的更改ShopModule为
@Module({
imports: [HttpModule],
controllers: [ShopController],
providers: [ShopService, PrismaService], // Prisma Service should probably come from PrisamModule
exports: [ShopService],
})
export class ShopModule {}
Run Code Online (Sandbox Code Playgroud)
和你QaModule的
@Module({
imports: [ShopModule],
controllers: [QaController],
providers: [QaService, PrismaService], // Prisma Service should still probably come from `PrismaModule`
})
export class QaModule {}
Run Code Online (Sandbox Code Playgroud)
服务只能在一个模块中声明,如果需要在其他地方使用,则应从该模块导出。在声明消费服务的模块中,应将原始模块添加到数组中imports。这将确保您只有每个非瞬态提供程序的一个实例,并且不需要在使用它的每个模块中重新创建
| 归档时间: |
|
| 查看次数: |
1200 次 |
| 最近记录: |