简体   繁体   English

从同一模块注入提供程序:无法解决依赖关系

[英]Injection of a provider from the same module: can't resolve dependencies

Bug Report错误报告

Current behavior当前行为

Getting error while instantiating the PaymentProcessorModule:实例化 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 */ ]
  })

However, both services come from the same module.但是,这两种服务都来自同一个模块。

Input Code输入代码

Here's my module:这是我的模块:

@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>,
  ) {}

  //...
}

And finally, PaymentProcessor:最后,支付处理器:

@Injectable()
export class PaymentProcessor {
  constructor(
    private transactions: TransactionsService,
    private payments: PaymentsService,
    private processor: ProcessingService,
  ) {}

  //...
}

Expected behavior预期行为

Expected to inject the TransactionsService.预计会注入 TransactionsService。 I could not seem to reproduce it in a sample repo, unfortunately.不幸的是,我似乎无法在示例回购中重现它。

Environment环境

Nest version: 7.4.1

The official support of NestJS told me that the PaymentProcessor must be mentioned in the imports array somewhere. NestJS 的官方支持告诉我PaymentProcessor必须在imports数组中的某个地方提到。 I checked for usages of the class and it's true, I accidentally imported the provider instead of the module in another context.我检查了 class 的用法,这是真的,我不小心在另一个上下文中导入了提供程序而不是模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM