我有一个名为FirebaseModule
导出 a的全局模块FirebaseService
,我将此模块导入到app.module.ts
,然后我尝试使用FirebaseService
内部 aUsersService
并且它因缺少依赖关系问题而失败。
有趣的是,如果我删除服务上的使用并仅在控制器上使用它,一切都会失败,但如果我想在服务提供者中使用它,它就会开始失败。
我的代码:
app.module.ts
@Module({
imports: [
CustomLoggerModule,
ConfigurationModule,
TypeOrmModule.forRootAsync({
useExisting: ConfigurationService,
}),
FirebaseModule,
UsersModule,
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
firebase.module.ts
@Global()
@Module({
imports: [],
providers: [FirebaseService],
exports: [FirebaseService],
})
export class FirebaseModule {}
users.module.ts
@Module({
imports: [CqrsModule, TypeOrmModule.forFeature([UsersRepository])],
controllers: [UsersController],
providers: [UsersService, ...CommandHandlers, ...EventHandlers],
exports: [UsersService, TypeOrmModule.forFeature([UsersRepository])],
})
export class UsersModule {}
users.controller.ts
@Controller('users')
@UseGuards(AuthGuard('firebase'))
export class UsersController {
constructor(
private readonly usersService: UsersService,
private readonly firebaseService: FirebaseService,
) {}
}
users.service.ts
@Injectable()
export class UsersService {
constructor(
private readonly firebaseService: FirebaseService,
private readonly repository: UsersRepository,
) {}
}
我收到以下错误:
Nest can't resolve dependencies of the UsersService (?, UsersRepository). Please make sure that the argument dependency at index [0] is available in the UsersModule context.