Skip to content
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

feat: request scoped provider aop support #25

Merged
merged 5 commits into from
Jul 24, 2023

Conversation

Istiopaxx
Copy link
Contributor

@Istiopaxx Istiopaxx commented Jul 20, 2023

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

  • I read and included theses actions below
  1. I have read the Contributing Guide
  2. I have written documents and tests, if needed.

- apply lazy decorators to prototype(by .prototype) of metatype(class)
- using ecmascript proxy to properly access this object in original func
@Istiopaxx Istiopaxx requested a review from WhiteKiwi July 20, 2023 15:54
@WhiteKiwi WhiteKiwi merged commit c347d33 into toss:main Jul 24, 2023
1 check passed
@WhiteKiwi
Copy link
Member

WhiteKiwi commented Jul 24, 2023

nestjs-aop에 기여해주셔서 감사합니다 :)
이해도가 높으신 것 같아서 nestjs-aop 어떻게 쓰시는지나 등등 해서 가볍게 커피챗 나누어보고 싶은데 혹시 연락드려도 괜찮을까요?

@Istiopaxx

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants