第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Nest 無(wú)法解析 BlahService 的依賴關(guān)系,盡管它是 Global()

Nest 無(wú)法解析 BlahService 的依賴關(guān)系,盡管它是 Global()

溫溫醬 2021-09-17 10:23:24
我有一個(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ù)。
查看完整描述

1 回答

?
喵喔喔

TA貢獻(xiàn)1735條經(jīng)驗(yàn) 獲得超5個(gè)贊

Using@Global()不會(huì)自動(dòng)解決循環(huán)依賴,你還是要@Inject(forwardRef(() => MyService))兩邊都用,看文檔


正如您自己指出的,循環(huán)依賴 ( forwardRef) 和全局模塊 ( @Global) 是糟糕的風(fēng)格,應(yīng)該避免。而是使您的依賴項(xiàng)明確。如果遇到循環(huán)依賴提取雙方導(dǎo)入的共享服務(wù)/模塊中的常用部分,請(qǐng)參閱此線程。


查看完整回答
反對(duì) 回復(fù) 2021-09-17
  • 1 回答
  • 0 關(guān)注
  • 404 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)