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

[RFC] 移除 app.getContainer,规范 Container 获取途径 #141

Closed
noahziheng opened this issue Jul 14, 2022 · 1 comment · Fixed by #142
Closed

[RFC] 移除 app.getContainer,规范 Container 获取途径 #141

noahziheng opened this issue Jul 14, 2022 · 1 comment · Fixed by #142

Comments

@noahziheng
Copy link
Member

目前通过 ctx/app 形式获取 Container 的形式是不统一的(app.getContainer() / ctx.container),希望做出如下统一:

  • 对于 ctx/app 上的取值统一为 container 属性(即 ctx.container / app.container
    • 对于用户的 set 行为(ctx.container = xxx)归类为不当使用,后期考虑通过 getter/setter
  • 对于经过 IoC 管理的类,统一通过 Inject 完成取值,代码如下:
// a_singleton_clazz.ts
import { Injectable, Inject, Container } from '@artus/injection';

@Injectable()
export default class MyClazz {
  @Inject()
  container: Container; // Supported by #139 
}

// a_execution_clazz.ts
import { Injectable, Inject, Container, ScopeEnum } from '@artus/injection';

@Injectable({
  scope: ScopeEnum.Execution
})
export default class MyClazz {
  @Inject()
  executionContainer: ExecutionContainer; // Will support
}
@noahziheng
Copy link
Member Author

属于 Breaking Change,考虑正式版发布后再想统一就更难,建议 Alpha 版本处理掉,需要 Check

@atian25 @hyj1991 @DuanPengfei @JerrysShan @Beace @wengeezhang

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.

1 participant