toss / nestjs-aop

A way to gracefully apply AOP to nestjs
MIT License
213 stars 24 forks source link

feat: request scoped provider aop support #25

Closed Istiopaxx closed 1 year ago

Istiopaxx commented 1 year ago

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

  1. I have read the Contributing Guide
  2. I have written documents and tests, if needed.
WhiteKiwi commented 1 year ago

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

Istiopaxx commented 1 year ago

네 좋습니다😄 chmhj9997@gmail.com 로 연락주세요