我检查了很多答案,但仍然出现此错误。我希望你能帮我看看我错过了什么
<块引用>错误:Nest 无法解析 BookingService 的依赖关系 (BookingRepository, ?, UserRepository)。请确保 索引 [1] 处的参数 TableRepository 在 BookingModule 上下文。可能的解决方案:
我的booking.service.ts:
@Injectable()
export class BookingService {
constructor(
@InjectRepository(Booking)
private readonly repository: Repository<Booking>,
@InjectRepository(Table)
private readonly tableRepository: Repository<Table>,
@InjectRepository(User)
private readonly userRepository: Repository<User>
) {}
}
我的app.module.ts:
@Module({
imports: [
TypeOrmModule.forRoot({ autoLoadEntities: true }),
TableModule,
RestaurantModule,
UserModule,
BookingModule
],
controllers: [AppController],
providers: [AppService],
exports: [TypeOrmModule]
})
export class AppModule {}
我的booking.module.ts:
@Module({
imports: [TypeOrmModule.forFeature([Booking]), TableModule],
controllers: [BookingController],
providers: [BookingService]
})
export class BookingModule {}
我的table.module.ts:
@Module({
imports: [TypeOrmModule.forFeature([Table])],
controllers: [TableController],
providers: [TableService],
exports: [TableService]
})
export class TableModule {}
答案 0 :(得分:1)
如果您想注入 TableRepository
,您应该将 TypeOrmModule.forFeature([Table])
添加到 BookingModule
,或者您应该将 TypeOrmModule
添加到 exports
TableModule
。后者只会创建 TableRepository
的一个实例,所以这是我的建议,但最终两者都会起作用。