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

装配操作可以指定数据源容器的加载策略 #63

Closed
Createsequence opened this issue Apr 18, 2023 · 2 comments
Closed

装配操作可以指定数据源容器的加载策略 #63

Createsequence opened this issue Apr 18, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@Createsequence
Copy link
Collaborator

Createsequence commented Apr 18, 2023

目前装配操作中的数据源容器加载模式总是通过 OperationAnnotationResolver 强制指定,也只有是或否两种选择,考虑到后续扩展,也许应当让它更灵活一点。

比如,我们可以将该值可以提供三个选项:

  • hungry:饿汉式加载,即配置解析时就立刻获取数据源容器,在 Opeartion 解析后就不可变;
  • lazy:懒加载,即当真正调用 AssembleOperation.getContainer 时再获取数据源容器,在 Opeartion 真正被调用后不可变;
  • prototype:每次调用 AssembleOperation.getContainer 都重新获取一次数据源容器,任何情况下都可变;

前两者没啥好说的,懒加载主要是为了支持一些数据源容器要在配置解析后才能注册的操作,具体参见 #50 ,而 everytime 则是为了支持一些会动态切换/刷新数据源的数据源容器,比如 #62 提到的这类容器提供者,当切换环境时装配操作应当有机会重新获得数据源容器。

其中,各类配置注解都可以加个可配置属性支持选择加载策略。

结合策略模式抽离为策略枚举也许会是一个好点子。

@Createsequence Createsequence added the enhancement New feature or request label Apr 18, 2023
@Createsequence Createsequence added this to the release 1.3.0 milestone Apr 18, 2023
@Createsequence Createsequence self-assigned this Apr 18, 2023
@Createsequence
Copy link
Collaborator Author

考虑到后续在 Cloud 环境下,可能会有刷新配置文件或者刷新 Bean 的需求,需要考虑引入一个类似 Spring 的 Scope 的机制,保证即使某个 Operation 绑定了一个 Container,我们依然可以在外部通过某些手段,更新 Container 中的数据,或者直接更新 Operation 的 Container 引用

@Createsequence
Copy link
Collaborator Author

2.0.0 重构后,获取容器的操作将会延迟到执行操作时,并且每次执行操作都会获取一次,因此不需要再纠结这个问题了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant