feat: request scoped provider aop support #25
Merged
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.
Overview
As request scoped providers and controllers are not supported, I added that.
In nest, request scoped instance wrappers uses their metatype when they instantiated, so modifying prototype of request scoped wrapper's metatype can modify the instantiated object's behavior.
reference: https://github.com/nestjs/nest/blob/67d4656623c7dc50f2cfd8d5e963678bcbf77959/packages/core/injector/injector.ts#L745-L757
I also changed applying aop wrapped function to original function by using ecma proxy, because wrapped function must bind request scoped wrapper's instance to original function' this object.. but when
onModuleInit
time, request did not arrived so aop executor can't access to instance of request scoped wrapper. Using proxy object can access the original function's this binding, and also proxy object deliver all of other stuffs(property access, other things..) to original function so it seems great for this usecase.PR Checklist