Pass action (request and response) when resolving middleware from container #1034
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
With in mind that resolving instances is done via:
When resolving controllers and interceptors
action
parameter is passed, while for middlewares it is not. Perhaps it should be consistent.My goal is to have a HTTP request scoped containers. Meaning, if I want to have an injectable class e.g.
RequestContext
which contains information about the request that other services can consume I must have only one instance per HTTP request for such class. I could achieve this by opening child container for each HTTP request and bind it as a constant. The problem is where to keep child container. My current thinking is it should be part of therequest
, like:Which works fine for e.g. controllers, but not for middlewares which have injected dependencies through a constructor. As a workaround I can in middleware
use
method resolve dependencies viarequest.iocContainer
.Checklist
Update index.md
)develop
)npm run prettier:check
passesnpm run lint:check
passes