NestJS中有三个模块:EndpointModule
,JWTModule
和特定的端点作为模块(例如InfoModule
)
我的EndpointModule看起来像这样:
@Module({
imports: [
JWTModule.withRSAKeys(
Path.resolveByApp('./private.key'),
Path.resolveByApp('./public.key')
),
InfoModule,
//More Endpoints
],
exports: [JWTModule]
})
export class EndpointModule {}
像这样的JWTModule:
@Module({
providers: [JWTService],
exports: [JWTService]
})
export class JWTModule {
static async withRSAKeys(
privateKeyPath: string,
publicKeyPath: string
): Promise<DynamicModule> {
return {
module: JWTModule,
providers: await this.createProviders(privateKeyPath, publicKeyPath)
};
}
如您所见,JWTModule
是一个动态模块。现在,我想将导出的JWTService
注入到我的端点控制器中。例如:
@Module({
controllers: [InfoController]
})
export class InfoModule {}
@Controller()
export class InfoController {
constructor(private jwt: JWTService){};
这不起作用。我必须将EndpointModule
导入InfoModule
中,但这会产生循环依赖关系。有什么办法可以避免这种情况?我应该重新订购模块吗?
答案 0 :(得分:0)
您需要在JWTModule
中导入InfoModule
或用EndpointModule
装饰Global()