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

[Feature]:useFactory 를 통한 LazyDecorator 공급자 등록 기능 #20

Closed
KIMBEOBWOO opened this issue Jun 9, 2023 · 4 comments · Fixed by #23
Closed

[Feature]:useFactory 를 통한 LazyDecorator 공급자 등록 기능 #20

KIMBEOBWOO opened this issue Jun 9, 2023 · 4 comments · Fixed by #23

Comments

@KIMBEOBWOO
Copy link

KIMBEOBWOO commented Jun 9, 2023

Overview

{
  provide: TRANSACTION_DECORATOR,
  useFactory: (dataSource: DataSource) => {
    const clsTransactionDacorator = new ClsHookedTransactinoDecorator(
      dataSource,
    );

    return clsTransactionDacorator;
  },
  inject: [getDataSourceToken(POSTGRES_CONNECTION)],
},

위와 같이 LazyDecorator 를 모듈 공급자로 등록하고, 등록할 LazyDecorator 는 아래와 같이 @aspect 를 구성했습니다.

@Aspect('TRANSACTION_DECORATOR')
export class ClsHookedTransactinoDecorator
  implements LazyDecorator<any, TransactionOptions>

하지만 해당 라이브러리의 lookupLazyDecorators 메서드에서

const aspect = this.reflector.get<string>(ASPECT, metatype);

의 결과가 undefined 라서 AOP 대상으로 찾아지지 않아 AOP 를 적용 할 수 없습니다. useFactory 로 인해 Aspect 메타데이터가 사라져서 그런것으로 이해됩니다. 혹시 제가 잘못 이해해 사용한 부분이 있다거나, 그렇지 않다면 향후 지원해주실 계획이 있는지 궁금합니다!

Describe the solution you'd like

<<LazyDecorator  모듈 공급자로 등록한 파일>>
  providers: [
    {
      provide: TRANSACTION_DECORATOR,
      useFactory: clsTransactionDacoratorFactory,
      inject: [getDataSourceToken(POSTGRES_CONNECTION)],
    },
  ],
})


Reflect.defineMetadata(
  ASPECT,
  TRANSACTION_DECORATOR,
  clsTransactionDacoratorFactory,
);

팩토리 메서드를 타깃으로 직접 메타데이터를 설정하는 방법

Additional context

@KIMBEOBWOO KIMBEOBWOO changed the title [Feature]:useFactory 를 통한 LazyDecorator 구현 클래스 주입 기능 [Feature]:useFactory 를 통한 LazyDecorator 공급자 등록 기능 Jun 9, 2023
@WhiteKiwi
Copy link
Member

제보 감사드립니다
metatype 또는 instace 의 prototype에서 뽑아오도록 수정하면 될 것 같습니다
수정해보겠습니다 :)

WhiteKiwi added a commit that referenced this issue Jun 19, 2023
…onal (#23)

* fix(#20): AopDecorator created using useFactory should also be functional

* chore: Migrate to pnpm 8
@WhiteKiwi
Copy link
Member

WhiteKiwi commented Jun 19, 2023

오늘중으로 2.0.3에 나갈 예정입니다
2.0.3으로 배포나갔습니다. 확인부탁드려요 :)

@KIMBEOBWOO
Copy link
Author

빠른 수정 감사합니다! 😄
혹시 npm 패키지 업데이트도 가능할까요??

@WhiteKiwi
Copy link
Member

WhiteKiwi commented Jun 19, 2023

헙 이럴수가 npm publish가 안되었네요 지금 해두겠슴다 확인 감사합니다
:done:

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 a pull request may close this issue.

2 participants