Issue
How can I get an injected object from the container in nestjs?
This is something in Spring (Java). We can get the objects from the container like this:
CustomerClass myClass = applicationContext.getBean("CustomerClass");
Do we have anything in NestJS like that?
Solution
Yes, that exists.
This is how you would retrieve a service called TaskService
from the app.
const app = await NestFactory.createApplicationContext(AppModule);
const tasksService = app.get(TasksService);
Of course you should always consider if you really need an instance of a service outside of the NestJs module system. If possible stay inside the application and inject the services.
Answered By - Tobias S.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.