I'm having some trouble injecting the mongoose Connection object inside a global interceptor in nest js. Here is my main module
imports: [
ConfigModule.forRoot({
isGlobal: true,
load: [getConfiguration]
}),
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
useFactory: (config: ConfigService) => config.get<TypeOrmModuleOptions>('postgres'),
inject: [ConfigService]
}),
MongooseModule.forRootAsync({
imports: [ConfigModule],
useFactory: (config: ConfigService) => {
const options = config.get('mongo');
const uri = `mongodb://${options.host}:${options.port}/${options.database}`;
return { uri };
},
inject: [ConfigService]
}),
OrderModule
],
controllers: [],
providers: [
{
provide: APP_INTERCEPTOR,
useClass: TransactionInterceptor
}
]
And here is the interceptor
@Injectable()
export class TransactionInterceptor implements NestInterceptor {
constructor(
private readonly pgConnection: PgConnection,
private readonly mongoConnection: MongoConnection
) {}
}
For some reasone Nest can't resolve only the mongoose dependecy. The typeorm connetion gets injected just fine. I also tried with an async provider like
@Injectable()
export class TransactionInterceptor implements NestInterceptor {
constructor(
private readonly pgConnection: PgConnection,
private readonly mongoConnection: MongoConnection
) {}
What am I missing? Thanks