@Vetoed public class WeldContainer extends AbstractCDI<Object> implements AutoCloseable, ContainerInstance
An new instance can be initialized using the Weld builder:
WeldContainer container = new Weld().initialize();
It's also possible to obtain the instance of a running container by id:
WeldContainer container = WeldContainer.instance("myCustomId");
shutdown()
must be always called to shutdown the container properly. AutoCloseable is implemented, so the container is automatically shut down when
leaving the try-with-resources block:
try (WeldContainer container = new Weld().initialize()) { container.select(Foo.class).get(); }
The container is also registered as a Singleton
bean.
Provides convenient access to beans, BeanManager and events, which is particularly helpful when bootstrapping an application in Java SE:
Foo foo = container.select(Foo.class).get(); container.getBeanManager().fireEvent(new Bar()) container.event().select(Bar.class).fire(new Bar());
Weld
knownClassNames
configuredProvider, discoveredProviders
Modifier and Type | Method and Description |
---|---|
void |
close() |
Event<Object> |
event()
Provides access to all events within the application.
|
BeanManager |
getBeanManager()
Provides direct access to the BeanManager.
|
String |
getId()
Weld containers must have a unique identifier assigned when there are multiple Weld instances running at once.
|
protected Instance<Object> |
getInstance()
Subclasses are allowed to override the default behavior, i.e. to cache instance per BeanManager.
|
static List<String> |
getRunningContainerIds() |
Instance<Object> |
instance()
Provides access to all beans within the application.
|
static WeldContainer |
instance(String id) |
boolean |
isRunning() |
void |
shutdown()
Shutdown the container.
|
destroy, get, getCallingClassName, isAmbiguous, isUnsatisfied, iterator, select, select, select
current, setCDIProvider
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEach, spliterator
public static WeldContainer instance(String id)
id
- null
if no such container existspublic static List<String> getRunningContainerIds()
public Instance<Object> instance()
public Event<Object> event()
weldContainer.event().select(Bar.class).fire(new Bar());
public String getId()
getId
in interface ContainerInstance
public BeanManager getBeanManager()
getBeanManager
in interface ContainerInstance
getBeanManager
in class CDI<Object>
public void shutdown()
shutdown
in interface ContainerInstance
Weld.initialize()
public boolean isRunning()
true
if the container was not shut down yet, false
otherwisepublic void close()
close
in interface AutoCloseable
protected Instance<Object> getInstance()
AbstractCDI
getInstance
in class AbstractCDI<Object>
Instance
the relevant calls are delegated toCopyright © 2015. All Rights Reserved.