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

refactor(loader): set default scope EXECUTION in module loader #177

Merged

Conversation

noahziheng
Copy link
Member

resolve #156

@codecov-commenter
Copy link

codecov-commenter commented Aug 17, 2022

Codecov Report

Merging #177 (9f4d4aa) into master (e8101f5) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #177   +/-   ##
=======================================
  Coverage   89.60%   89.61%           
=======================================
  Files          51       51           
  Lines        1097     1098    +1     
  Branches      188      188           
=======================================
+ Hits          983      984    +1     
  Misses        114      114           
Impacted Files Coverage Δ
src/loader/impl/module.ts 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@@ -17,6 +17,7 @@ class ModuleLoader implements Loader {
const opts: Partial<InjectableDefinition> = {
path: item.path,
type: moduleClazz,
scope: ScopeEnum.EXECUTION, // The class used with @artus/core will have default scope EXECUTION, can be overwritten by Injectable decorator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果定义过 scope 的 class 会不会有问题

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

通过 Injectable 装饰器定义的 scope 优先级会比这个更高,这样貌似覆盖不了

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要调整下 Injectable 的行为

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我确认下这里的逻辑

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

injection 也有处得改的 https://github.com/artusjs/injection/blob/master/src/decorator/injectable.ts#L7

优先级顺序:用户显式在 Injectable 传递 => containet.set 指定的 => set 方法内部在没有 scope 参数时的默认值(SINGLETON)

Copy link
Member

@hyj1991 hyj1991 Aug 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JerrysShan https://github.com/artusjs/injection/blob/master/src/container.ts#L67

看起来如果定义了 id 的,scope 就强制使用了 options.scope 了,不太确定 class 会不会有这样的逻辑

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JerrysShan 看下我上面发的那个逻辑有没有可能会在 module loader class 的时候走到

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JerrysShan https://github.com/artusjs/injection/blob/master/src/container.ts#L67

看起来如果定义了 id 的,scope 就强制使用了 options.scope 了,不太确定 class 会不会有这样的逻辑

应该说走了 value 的,但是设置 value 不会通过 Injectable ,通过 options 没问题

@hyj1991 hyj1991 merged commit f3e5a2f into artusjs:master Aug 17, 2022
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.

[RFC] 针对 Module Loader 处理的类调整默认 Scope
5 participants