The dependency injection uses Singleton instances
I would like to be able to specify the lifetime of the dependency being injected
Something like - https://github.com/jeffijoe/awilix#lifetime-management
On a related note, why does nestjs implement its own dependency injection framework rather than using something like typedi or inversify or awilix?
Nestjs implements its own injection framework. I think @Meir017 is requesting the lifetime feature of awilix (singleton, scoped and transient modes)
@xxxtonixxx I understand that nestjs implements its own, I'm asking why it does that instead of using existing solution like typedi
.
I'm talking about something similar to https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-2.1#service-lifetimes
This would allow me to pass parameters for each request
for example: add to the logging a request-id to trace actions related to that request
I think your questions answers themselves.
The architecture is supposed to be as close to Angulars as possible.
That cannot be done using awilix, inversify or any other library for that matter because this DI is obviously built around the module architecture.
This framework is inspired by Angular that doesn't mean it can't or shouldn't improve certian features Angular has.
I'm not sure how relevant the concept of sevices lifetime is in Angular
There's already TRANSIENT and SINGLETON management.
I mean I can see why you'd want hierarchy (SCOPED) dependent lifetime management, but really, how many use cases are there?
https://github.com/nestjs/nest/blob/master/packages/common/decorators/modules/single-scope.decorator.ts
Once async-hooks
feature (it is still experimental in node 10) is stable, we'll think about providing a built-in solution for request-scoped instances.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Once
async-hooks
feature (it is still experimental in node 10) is stable, we'll think about providing a built-in solution for request-scoped instances.