-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[inversify-express-utils] allow to inject dependencies into middleware constructor #368
Comments
hey @b1ff . I saw that you've made a PR for this. but it's already possible to do this in
And then for the container binding
Is this what you were looking for ? |
@PodaruDragos hey there, not really. The issue is when I do this.bind(..).to...(); in middleware, I cannot inject it using constructor to middleware. I have to use |
Expected Behavior
Middlewares should be created by http request scoped container.
Since by default they are not singleton it does make sense to create them using per-request container, which allows to inject request-scoped dependencies in constructor instead calling
this.httpContext.container.get(...)
. For middlewares that are registered as singleton nothing will be changed, so it should add any performance difference.Current Behavior
Right now middlewares in express-utils are always created using root container which does not allow to inject request scoped variables in constructor.
Possible Solution
PR: https://github.com/inversify/inversify-express-utils/pull/325/files
Steps to Reproduce (for bugs)
Context
In application I would like to register some values in middlewares at the beginning of the request and then use classes that abstract HTTP specific things for the consumers. Allowing to inject dependencies into middleware constructor simplifies unit testing of those middlewares.
Your Environment
NodeJS 12.x.x
Windows
The text was updated successfully, but these errors were encountered: