实例化PaymentProcessorModule时出错:
Error: Nest can't resolve dependencies of the PaymentProcessor (?, PaymentsService, ProcessingService). Please make sure that the argument TransactionsService at index [0] is available in the PaymentProcessor context.
Potential solutions:
- If TransactionsService is a provider, is it part of the current PaymentProcessor?
- If TransactionsService is exported from a separate @Module, is that module imported within PaymentProcessor?
@Module({
imports: [ /* the Module containing TransactionsService */ ]
})
但是,两种服务都来自同一模块。
这是我的模块:
@Module({
imports: [
TypeOrmModule.forFeature([ Transaction ]),
],
providers: [
PaymentProcessor,
TransactionsService,
TransactionsResolver,
],
exports: [PaymentProcessor],
})
export class PaymentProcessorModule {}
TransactionService:
@Injectable()
export class TransactionsService {
constructor(
@InjectRepository(Transaction) private transRepo: Repository<Transaction>,
) {}
//...
}
最后是PaymentProcessor:
@Injectable()
export class PaymentProcessor {
constructor(
private transactions: TransactionsService,
private payments: PaymentsService,
private processor: ProcessingService,
) {}
//...
}
预计将注入TransactionsService。不幸的是,我似乎无法在示例回购中复制它。
Nest version: 7.4.1
答案 0 :(得分:1)
NestJS的官方支持告诉我,PaymentProcessor
数组中必须在某个地方提到imports
。我检查了类的用法,这是真的,我不小心导入了提供程序,而不是在另一个上下文中导入了模块。