-
Notifications
You must be signed in to change notification settings - Fork 16
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
refactor(loader): set default scope EXECUTION in module loader #177
Conversation
Codecov Report
@@ 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
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果定义过 scope 的 class 会不会有问题
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
通过 Injectable 装饰器定义的 scope 优先级会比这个更高,这样貌似覆盖不了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要调整下 Injectable 的行为
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我确认下这里的逻辑
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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 会不会有这样的逻辑
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JerrysShan 看下我上面发的那个逻辑有没有可能会在 module loader class 的时候走到
There was a problem hiding this comment.
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 没问题
resolve #156