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] Loader 需要支持具名导出 injectable 类的扫描 #163

Closed
hyj1991 opened this issue Aug 5, 2022 · 2 comments · Fixed by #180
Closed

[RFC] Loader 需要支持具名导出 injectable 类的扫描 #163

hyj1991 opened this issue Aug 5, 2022 · 2 comments · Fixed by #180

Comments

@hyj1991
Copy link
Member

hyj1991 commented Aug 5, 2022

背景

目前的 artus/core 在扫描期和启动期不会扫描和加载非 export default 类,这种设计在实践中给初次使用方带来一个困扰,例如:

@Injectable()
export class MyService {

}

这个标记为可注入的 MyService 在实际使用中无法 Inject,考虑到 TypeScript 社区生态的使用习惯,需要在默认导出之外对具名导出也进行支持

@hyj1991
Copy link
Member Author

hyj1991 commented Aug 5, 2022

经过 8.05 上午主要涉及方飞书会议讨论,结论如下:

  • artus/core 需要支持具名导出

8.8 之前快速支持方案:

  • 通过预留的可选 loaderState 在扫描期将可被注入的具名导出 class name 作为数组写入,启动期通过 class name 直接加载到 container 中,以不影响启动期的执行性能 @hyj1991
  • Scanner 提供额外属性控制 @hyj1991
    • 不做任何限制
    • 限制只能扫描具名导出
    • 限制只能扫描默认导出(兼容之前的方案)

由于目前的 Scanner 实现比较复杂,和 Loader 模块耦合过深,这一部分需要进行重构,需要梳理后给出改造方案,提供一个更加完善的实现后再将此能力在文档中透出 @noahziheng

@hyj1991
Copy link
Member Author

hyj1991 commented Aug 5, 2022

8.05 RFC 讨论信息:

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