@Vetoed public class WeldContainer extends org.jboss.weld.AbstractCDI<Object> implements AutoCloseable, ContainerInstance, javax.enterprise.inject.se.SeContainer
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| Modifier and Type | Method and Description |
|---|---|
protected void |
checkState() |
void |
close() |
static WeldContainer |
current()
A convenient method for
CDI.current(). |
org.jboss.weld.events.WeldEvent<Object> |
event()
Provides access to all events within the application.
|
javax.enterprise.inject.spi.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 org.jboss.weld.inject.WeldInstance<Object> |
getInstance() |
static List<String> |
getRunningContainerIds() |
javax.enterprise.inject.Instance<Object> |
instance()
Deprecated.
Applications are encouraged to use methods for programmatic lookup directly.
|
static WeldContainer |
instance(String id) |
boolean |
isRunning() |
void |
shutdown()
Shutdown the container.
|
destroy, get, getCallingClassName, getHandler, getPriorityComparator, handlers, isAmbiguous, isResolvable, isUnsatisfied, iterator, select, select, select, selectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitdestroy, isAmbiguous, isResolvable, isUnsatisfied, select, select, select, streamforEach, iterator, spliteratorpublic static WeldContainer instance(String id)
id - null if no such container existspublic static WeldContainer current()
CDI.current(). Returns current WeldContainer instance
if there is exactly one instance running. Throws IllegalStateException in any other case.WeldContainer instance if and only if exactly one instance exists{@link - IllegalStateException} if there is 0 or more than 1 instance runningpublic static List<String> getRunningContainerIds()
public javax.enterprise.inject.Instance<Object> instance()
Instance.public org.jboss.weld.events.WeldEvent<Object> event()
weldContainer.event().select(Bar.class).fire(new Bar());
public String getId()
getId in interface ContainerInstancepublic javax.enterprise.inject.spi.BeanManager getBeanManager()
getBeanManager in interface javax.enterprise.inject.se.SeContainergetBeanManager in interface ContainerInstancegetBeanManager in class javax.enterprise.inject.spi.CDI<Object>public void shutdown()
shutdown in interface ContainerInstanceWeld.initialize()public boolean isRunning()
isRunning in interface javax.enterprise.inject.se.SeContainertrue if the container was initialized completely and is not shut down yet, false otherwisepublic void close()
close in interface AutoCloseableclose in interface javax.enterprise.inject.se.SeContainerprotected org.jboss.weld.inject.WeldInstance<Object> getInstance()
getInstance in class org.jboss.weld.AbstractCDI<Object>protected void checkState()
checkState in class org.jboss.weld.AbstractCDI<Object>Copyright © 2019. All rights reserved.