What will happen if I declare a service as provider in a module but did not use @Injectable decorator in the service?
//Module
module({
controller: [catController],
provider: [catService]
})
//Service
//@Injectable()
export class catService{
}
What I think is that a token will be registered but not be used and new instance will be shared every time. Am I correct?
@Injectable()
is an interesting case, as what it does is tell NestJS that this class needs to have dependencies injected into it. Technically, this decorator can be omitted if there are no dependencies to inject, but at the risk of no longer being uniform with the rest of the framework. Otherwise, the class itself will act as any other NestJS provider and can still be injected into other controllers and providers.