NestJS 8 - Inject Service without constructor

82 Views Asked by At

I'm trying to load config using ConfigModule as below

 ConfigModule.forRoot({
      ignoreEnvFile: true,
      isGlobal: true,
      load: [async () => await fetchConfig(new ServiceConfigurationService())],
    }),

Inside ServiceConfigurationService class I want to inject other service class which I have exposed through a npm module. Is there any way to inject service instead through a constructor? I have tried property bases DI, it doesn't work in my case.

1

There are 1 best solutions below

0
Micael Levi On

as long as you control the initialization of ServiceConfigurationService by yourself, you can use any tool to perform the injection.

But if you want to use nestjs's DI container, you must do that through nestjs providers as the docs shown here: https://docs.nestjs.com/providers