#TestModule error with forwardRef
12 messages · Page 1 of 1 (latest)
should be:
@Inject(forwardRef(() => WalletService))
private readonly walletService: WalletService,
@InjectRepository(WalletTransaction, 'pg-wallet')
private walletTransactionRepository: Repository<WalletTransaction>,
I have updated this:
export class WalletTransactionService {
constructor(
@InjectRepository(WalletTransaction, 'pg-wallet')
private walletTransactionRepository: Repository<WalletTransaction>,
@Inject(forwardRef(() => WalletService))
private readonly walletService: WalletService,
private readonly notificationGateway: NotificationGateway,
private readonly metricsService: MetricsService,
private readonly bankService: BankService,
private readonly userService: UserService,
) {}
Now I get an error:
Nest can't resolve dependencies of the WalletTransactionService (pg-wallet_WalletTransactionRepository, WalletService, NotificationGateway, MetricsService, BankService, ?). Please make sure that the argument dependency at index [5] is available in the RootTestModule context.
My module looks like this:
@Module({
imports: [
// .. other imports,
forwardRef(() => UserModule),
],
// ...,
})
Why do I get an error from a service whose module is imported via forwardRef?
@brazen crystal
because of UserService being circular, I guess
User module
@Module({
imports: [
forwardRef(() => WalletModule),
],
providers: [UserService, UserProcessor],
exports: [UserRepositories, UserService],
})
export class UserModule {}
use forwardRef for that injected UserService as well
Yes, it worked. Is this a nestjs bug?
This post has been marked as resolved. :white_check_mark:
Please read through the conversation and resolution if you are having the same issue, and then re-open the post if you are still having trouble, providing as much extra information as possible.
I didn't see this in the documentation. Hmm(