|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.myfaces.extensions.cdi.core.api.provider.BeanManagerProvider
public class BeanManagerProvider
This class provides access to the BeanManager by registring the current BeanManager in an extension and making it available via a singleton factory
This is really handy if you like to access CDI functionality from places where no injection is available.
Usage:
BeanManager bm = BeanManagerProvider.getInstance().getBeanManager();
Constructor Summary | |
---|---|
BeanManagerProvider()
|
Method Summary | ||
---|---|---|
void |
cleanupStoredBeanManagerOnShutdown(javax.enterprise.inject.spi.BeforeShutdown beforeShutdown)
Cleanup on container shutdown |
|
javax.enterprise.inject.spi.BeanManager |
getBeanManager()
The active BeanManager for the current ClassLoader |
|
|
getContextualReference(Class<T> type,
Annotation... qualifiers)
Get a Contextual Reference by it's type and annotation. |
|
|
getContextualReference(Class<T> type,
String name)
Get a Contextual Reference by it's EL Name. |
|
static BeanManagerProvider |
getInstance()
Singleton accessor |
|
static boolean |
isActive()
Returns if the BeanManagerProvider has been initialized |
|
void |
setBeanManager(javax.enterprise.inject.spi.AfterBeanDiscovery afterBeanDiscovery,
javax.enterprise.inject.spi.BeanManager beanManager)
It basiscally doesn't matter which of the system events we use, but basically we |
|
void |
setRootBeanManager(javax.enterprise.inject.spi.BeanManager beanManager)
|
|
protected void |
setTestMode()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public BeanManagerProvider()
Method Detail |
---|
public static boolean isActive()
BeanManagerProvider
has been initialized
public static BeanManagerProvider getInstance()
public javax.enterprise.inject.spi.BeanManager getBeanManager()
BeanManager
for the current ClassLoader
public <T> T getContextualReference(Class<T> type, Annotation... qualifiers)
Attention: You shall not use this method to manually resolve a
@Dependent bean! The reason is that this contextual instances do usually
live in the well defined lifecycle of their injection point (the bean they got
injected into). But if we manually resolve a @Dependent bean, then it does not
belong to such a well defined lifecycle (because @Dependent it is not
@NormalScoped) and thus will not automatically be
destroyed at the end of the lifecycle. You need to manually destroy this contextual instance via
Contextual.destroy(Object, javax.enterprise.context.spi.CreationalContext)
.
Thus you also need to manually store the CreationalContext and the Bean you
used to create the contextual instance which this method will not provide.
T
- target typetype
- the type of the bean in questionqualifiers
- additional qualifiers which further distinct the resolved bean
public <T> T getContextualReference(Class<T> type, String name)
Get a Contextual Reference by it's EL Name. This only works for beans with the @Named annotation.
Attention: please see the notes on manually resolving @Dependent bean
in getContextualReference(Class, java.lang.annotation.Annotation...)
!
T
- target typetype
- the type of the bean in question - only use Object.class if the type is unknown in dyn. use-casesname
- the EL name of the bean
public void setBeanManager(@Observes javax.enterprise.inject.spi.AfterBeanDiscovery afterBeanDiscovery, javax.enterprise.inject.spi.BeanManager beanManager)
afterBeanDiscovery
- event which we don't actually use ;)beanManager
- the BeanManager we store and make available.public void setRootBeanManager(javax.enterprise.inject.spi.BeanManager beanManager)
public void cleanupStoredBeanManagerOnShutdown(@Observes javax.enterprise.inject.spi.BeforeShutdown beforeShutdown)
beforeShutdown
- cdi shutdown eventprotected void setTestMode()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |