Javascript 从同一模块注入一个提供程序:can';无法解析依赖项 错误报告 当前行为
实例化PaymentProcessorModule时出错:Javascript 从同一模块注入一个提供程序:can';无法解析依赖项 错误报告 当前行为,javascript,typescript,dependency-injection,nestjs,Javascript,Typescript,Dependency Injection,Nestjs,实例化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. P
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 {}
交易服务:
@Injectable()
export class TransactionsService {
constructor(
@InjectRepository(Transaction) private transRepo: Repository<Transaction>,
) {}
//...
}
预期行为
预期将注入TransactionService。不幸的是,我似乎无法在回购协议样本中复制它
环境
NestJS的官方支持告诉我,
PaymentProcessor
必须在imports
数组的某个地方提到。我检查了类的用法,确实,我意外地在另一个上下文中导入了提供程序而不是模块
@Injectable()
export class PaymentProcessor {
constructor(
private transactions: TransactionsService,
private payments: PaymentsService,
private processor: ProcessingService,
) {}
//...
}
Nest version: 7.4.1