是否有可能破坏CDI范围? [英] Is it possible to destroy a CDI scope?
问题描述
我正在开发一个Java EE应用程序,主要是带有JSF管理控制台的JAX-RS,它使用CDI / Weld进行依赖注入 javax.enterprise.context.ApplicationScoped
个对象。除了一些小的调试问题,CDI已经为这个项目做了很好的工作。
I'm working on a Java EE application, primarily JAX-RS with a JSF admin console, that uses CDI/Weld for dependency injection with javax.enterprise.context.ApplicationScoped
objects. Minor debugging issues aside, CDI has worked beautifully for this project.
现在我需要对CDI注入的对象生命周期进行一些非常粗粒度的控制。我需要能够:
Now I need some very coarse-grained control over CDI-injected object lifecycles. I need the ability to:
- 从应用程序上下文中删除一个注入的对象,或
- 销毁/删除/清除/重置/删除整个应用程序上下文,或
- 定义我自己的
@ScopeType
并实现上下文
我可以提供执行上述两项任务之一的方法。
- Remove an injected object from the application context, or
- Destroy/delete/clear/reset/remove the entire application context, or
- Define my own
@ScopeType
and implementingContext
in which I could provide methods to perform one of the two above tasks.
我完全清楚这是如果不是反对的话,CDI和依赖注入的范围一般。我只想知道
I'm fully aware that this is across, if not against, the grain of CDI and dependency injection in general. I just want to know
- 这是远程可能吗?
- 如果是,最简单的是什么/最简单/最快/最愚蠢的方式完成工作?
推荐答案
自定义范围可能适合您的需求可以在 https://github.com/openknowledge/openknowledge-cdi-extensions/tree/master/openknowledge-cdi-scope/src/main/java/de/openknowledge/cdi/scope 也许你必须稍微调整一下实现。
A custom scope which might fit your needs is available at https://github.com/openknowledge/openknowledge-cdi-extensions/tree/master/openknowledge-cdi-scope/src/main/java/de/openknowledge/cdi/scope Maybe you have to adjust the implementation a bit.
这篇关于是否有可能破坏CDI范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!