public class BeanManagerProvider extends Object implements javax.enterprise.inject.spi.Extension
BeanManagerby registering the current
BeanManagerin an extension and making it available via a singleton factory for the current application.
This is really handy when you need to access CDI functionality from places where no injection is available.
If a simple but manual bean lookup is needed, it's easier to use the
As soon as an application shuts down, the reference to the
BeanManager is removed.
BeanManager bm = BeanManagerProvider.getInstance().getBeanManager();
Attention: This approach is intended for use in user code at runtime. If BeanManagerProvider is used during
Container boot (in an Extension), non-portable behaviour results. During bootstrapping, an Extension shall
@Inject BeanManager to get access to the underlying BeanManager (see e.g.
This is the only way to guarantee that the right BeanManager is obtained in more complex Container scenarios.
|Constructor and Description|
|Modifier and Type||Method and Description|
By cleaning the final BeanManager map after the deployment gets validated, premature loading of information from JNDI is prevented in cases where the container might not be fully setup yet.
Cleanup on container shutdown.
Returns the current provider instance which provides access to the current
Indicates whether the
It doesn't really matter which of the system events is used to obtain the BeanManager, but
public static boolean isActive()
BeanManagerProviderhas been initialized. Usually it's not necessary to call this method in application code. It's useful e.g. for other frameworks to check if DeltaSpike and the CDI container in general have been started.
public static BeanManagerProvider getInstance()
public void setBeanManager(@Observes javax.enterprise.inject.spi.AfterBeanDiscovery afterBeanDiscovery, javax.enterprise.inject.spi.BeanManager beanManager)
AfterBeanDiscoveryhas been chosen since it allows all events which occur after the
AfterBeanDiscoveryto use the
afterBeanDiscovery- event which we don't actually use ;)
beanManager- the BeanManager we store and make available.
public javax.enterprise.inject.spi.BeanManager getBeanManager()
BeanManagerfor the current application (current
ClassLoader). This method will throw an
IllegalStateExceptionif the BeanManager cannot be found.
IllegalStateException- if the BeanManager cannot be found
public void cleanupFinalBeanManagers(@Observes javax.enterprise.inject.spi.AfterDeploymentValidation adv)
public void cleanupStoredBeanManagerOnShutdown(@Observes javax.enterprise.inject.spi.BeforeShutdown beforeShutdown)
beforeShutdown- CDI shutdown event
Copyright © 2018 The Apache Software Foundation. All rights reserved.