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.
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 implementingContext
in which I could provide methods to perform one of the two above tasks.
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
- Is this remotely possible?
- If yes, what is the easiest/simplest/quickest/foolproofiest way to get the job done?