I'm trying to inject a custom provider as per the documentation:
https://docs.nestjs.com/fundamentals/custom-providers
My service:
@Injectable({scope: Scope.REQUEST})
export class ReportService implements OnModuleInit {
private readonly reportRepository: Repository<Report>;
constructor(
public config: ConfigService,
private readonly moduleRef: ModuleRef,
@Inject('CONNECTION') connection: Connection,
) {
console.log(connection);
}
...
app.module.ts:
const connectionProvider = {
provide: 'CONNECTION',
useValue: connection,
};
@Module({
imports: [
ReportModule,
...
],
providers: [connectionProvider],
controllers: [AppController],
})
export class AppModule implements NestModule {
Doing so results in:
Error: Nest can't resolve dependencies of the ReportService (ConfigService, ModuleRef, ?). Please make sure that the argument at index [2] is available in the ReportModule context.
What am I missing?
app.module.ts. Perhaps I need to add config toReportModue? - nurikabeAppModuleinto the modules that want to use them. See my answer. - KenavR