I have been using NestJS for the past 4 months after working with PHP for 5 years, mainly with Symfony. With PHP, I had the ability to access the compiled DI container and retrieve any necessary service from it.
For example, in an application with services (A, B, C) where A depends on B and C, I could easily call the container in controllers or other services that were aware of it, and utilize the compiled A or C services as needed.
Is there a similar option in NestJS DI to call a specific service by some ID? I've tried looking for it, but all my searches lead to using compiled services only without direct access.
UPD: I am curious about accessing the DI container from a non-@Injectible class. For instance:
export class StatefulCruncherClass{
constructor(private dataToCrunch:any){
}
async crunch(){
if (this.dataToCrunch.isObject){
return NestJs.getDI().get('ObjectsCruncher').crunch(this)
} else {
return NestJs.getDI().get('ArrayCruncher').crunch(this)
}
}
}