我将所有与数据库相关的操作移到了一个独立的模块中:
@Module({
imports: [
TypeOrmModule.forFeature([
PostRepository,
UserRepository,
CommentRepository,
]),
],
exports: [PostRepository, UserRepository, CommentRepository],
providers: [PostsDataInitializer],
})
export class DatabaseModule {}
但在其他模块中,当我导入 DatabaseModule
并尝试在服务类中注入 PostRepository
时,出现以下错误。
Nest cannot export a provider/module that is not a part of the currently processed module (DatabaseModule).
Please verify whether the exported PostRepository is available in this particular context.
答案 0 :(得分:1)
阅读some of my Angular codes后自己解决了,只需要将TypeOrmModule
中的DatabaseModule
导出即可。
@Module({
imports: [
TypeOrmModule.forFeature([
PostRepository,
UserRepository,
CommentRepository,
]),
],
exports: [TypeOrmModule],
providers: [PostsDataInitializer],
})
export class DatabaseModule {}