是否有可能破坏CDI范围? [英] Is it possible to destroy a CDI scope?

查看:170
本文介绍了是否有可能破坏CDI范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个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:

  • Remove an injected object from the application context, or
  • Destroy/delete/clear/reset/remove the entire application context, or
  • Define my own @ScopeType and implementing Context 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆