我有一個(gè) NestJS 問題,它似乎只適用于 1 個(gè)模塊,其他所有模塊都可以正常工作。我有以下模塊。錯(cuò)誤是:[ExceptionHandler] Nest can't resolve dependencies of the ApplicationService (ApplicationModel, AwsService, UserService, ?, JobService). Please make sure that the argument at index [3] is available in the ApplicationModule context.該AgencyService是[3]。如果我AgencyModule從ApplicationModuleNestJS 中刪除成功編譯,我可以進(jìn)行 API 調(diào)用。AgencyModule,ApplicationModule,AuthModule,JobModule,UserModule,所有這些模塊都是他們的服務(wù)提供商的其他模塊所需要的,所以不要使用forwardRef()我剛剛制作的方法在彼此之間導(dǎo)入它們Global()- 可能不是最佳實(shí)踐,但嘿嘿(它有效)。我的AppModule檔案。@Module({ imports: [ MongooseModule.forRootAsync({ useFactory: (configService: ConfigService) => ({ uri: configService.get('MONGO_DB_URL'), useNewUrlParser: true, }), imports: [ConfigModule], inject: [ConfigService], }), ConfigModule, AgencyModule, ApplicationModule, AuthModule, DevModule, JobModule, UserModule, VideoModule, ], controllers: [AppController], providers: [AppService],})export class AppModule {}每個(gè)模塊文件夾具有以下結(jié)構(gòu)。agency/- dto/- agency.controller.ts- agency.interface.ts- agency.schema.ts- agency.service.ts- agency.module.ts我的AgencyModule檔案。@Global()@Module({ imports: [ SharedModule, MongooseModule.forFeature([{ name: 'Agency', schema: AgencySchema }]), ], controllers: [ AgencyController, ], providers: [ AgencyService, AwsService, ], exports: [ AgencyService, ],})export class AgencyModule implements NestModule { public configure(consumer: MiddlewareConsumer) { consumer .apply() .forRoutes( { path: 'agency', method: RequestMethod.GET }, ); }}我的AgencyService檔案。@Injectable()export class AgencyService { constructor( @InjectModel('Agency') private readonly agencyModel: Model<Agency>, private readonly awsService: AwsService, private readonly applicationService: ApplicationService, ) { // } // More stuff here but not worth adding to the snippet.}這AwsService是一個(gè)沒有模塊的共享服務(wù)。
Nest 無(wú)法解析 BlahService 的依賴關(guān)系,盡管它是 Global()
溫溫醬
2021-09-17 10:23:24