我想在ConfigService上使用CustomerRepository。
所以,我这样尝试
export class CrawlerRepository extends Repository<Crawler> {
constructor(
private readonly config: ConfigService,
) { super(); }
}
但是它不起作用。(我认为因为自定义存储库无法由nestjs实例化)
如何在CustomRepository中访问ConfigService?
答案 0 :(得分:0)
因此要在存储库中使用DI,存储库本身必须是可注射的。
@Injectable()
export class CrawlerRepository extends Repository<Crawler> {
constructor(private readonly config: ConfigService) {
super();
}
}
然后将CrawlerRepository
作为提供者添加到模块中
@Module({
providers: [CrawlerRepository],
})
export class AppModule {}
在实例化CrawlerRepository之前,模块还需要导入ConfigService。