Внедрение провайдера из того же модуля: не удается разрешить зависимости - PullRequest
0 голосов
/ 05 августа 2020

Отчет об ошибке

Текущее поведение

Получение ошибки при создании экземпляра 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. К сожалению, мне не удалось воспроизвести его в образце репозитория.

Environment

Nest version: 7.4.1

1 Ответ

1 голос
/ 05 августа 2020

Официальная поддержка Nest JS сказала мне, что PaymentProcessor должен быть где-то упомянут в массиве imports. Я проверил использование класса, и это правда, я случайно импортировал поставщика вместо модуля в другой контекст.

...