2

Questions about a ConfigService in documentation: https://docs.nestjs.com/techniques/configuration#service

See the class definition there:

export class ConfigService { /* ... */ }

Why there is no @Injectable decorator? Is there any reason or just a mistake? Has @Injectable decorator any impact on a fact the module that provides ConfigService might be @Global?

Mateusz
  • 27
  • 3

1 Answers1

1

there is no @Injectable decorator because this class is used as a custom provider. See follow the usage:

{
  provide: ConfigService,
  useValue: new ConfigService(`${process.env.NODE_ENV}.env`),
},

In that case, your able to specify the token and the value that you want to use, here the configService is instantiate manually and not by the DI system.

When you use the @Injectable decorator you tell to nestjs that this class as to be instantiate by the framework.

I hope this will help you to understand.

Adrien De Peretti
  • 3,342
  • 16
  • 22
  • So, here we instantiate the service class already in a module, therefore "Injectable" decorator is not applied. I've ended up in those articles too: https://docs.nestjs.com/fundamentals/custom-providers and https://docs.nestjs.com/providers#custom-providers Thanx @adrien-de-peretti, that was helpful. – Mateusz May 28 '19 at 22:00
  • My pleasure, if the answer help you can you mark it as resolved to be seen by anybody else if they have the same question. Thank you – Adrien De Peretti May 29 '19 at 10:31
  • You should be able to put the answer as valid – Adrien De Peretti May 29 '19 at 22:04