Package org.jboss.weld.environment.se
Class WeldContainer
java.lang.Object
jakarta.enterprise.inject.spi.CDI<T>
org.jboss.weld.AbstractCDI<Object>
org.jboss.weld.environment.se.WeldContainer
- All Implemented Interfaces:
jakarta.enterprise.inject.Instance<Object>,jakarta.enterprise.inject.se.SeContainer,jakarta.inject.Provider<Object>,AutoCloseable,Iterable<Object>,ContainerInstance,org.jboss.weld.inject.WeldInstance<Object>
@Vetoed
public class WeldContainer
extends org.jboss.weld.AbstractCDI<Object>
implements AutoCloseable, ContainerInstance, jakarta.enterprise.inject.se.SeContainer
Represents a Weld SE container.
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().getEvent().select(Bar.class).fire(new Bar) container.event().select(Bar.class).fire(new Bar());
- Author:
- Peter Royle, Martin Kouba
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface jakarta.enterprise.inject.Instance
jakarta.enterprise.inject.Instance.Handle<T extends Object>Nested classes/interfaces inherited from interface org.jboss.weld.inject.WeldInstance
org.jboss.weld.inject.WeldInstance.Handler<T extends Object> -
Field Summary
Fields inherited from class org.jboss.weld.AbstractCDI
knownClassNamesFields inherited from class jakarta.enterprise.inject.spi.CDI
configuredProvider, discoveredProviders -
Method Summary
Modifier and TypeMethodDescriptionprotected voidvoidclose()static WeldContainercurrent()A convenient method for {@link CDI.current()}.org.jboss.weld.events.WeldEvent<Object>event()Provides access to all events within the application.jakarta.enterprise.inject.spi.BeanManagerProvides direct access to the BeanManager.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>jakarta.enterprise.inject.Instance<Object>instance()Deprecated, for removal: This API element is subject to removal in a future version.Applications are encouraged to use methods for programmatic lookup directly.static WeldContainerbooleanvoidshutdown()Shutdown the container.Methods inherited from class org.jboss.weld.AbstractCDI
destroy, get, getCallingClassName, getHandle, getHandlePriorityComparator, getHandler, getPriorityComparator, handlers, handles, isAmbiguous, isResolvable, isUnsatisfied, iterator, select, select, select, selectMethods inherited from class jakarta.enterprise.inject.spi.CDI
getBeanContainer, setCDIProviderMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jakarta.enterprise.inject.Instance
destroy, getHandle, handles, handlesStream, isAmbiguous, isResolvable, isUnsatisfied, streamMethods inherited from interface java.lang.Iterable
forEach, iterator, spliteratorMethods inherited from interface jakarta.inject.Provider
getMethods inherited from interface jakarta.enterprise.inject.se.SeContainer
getBeanContainerMethods inherited from interface org.jboss.weld.inject.WeldInstance
handlersStream
-
Method Details
-
instance
- Parameters:
id-- Returns:
- the running container with the specified identifier or
nullif no such container exists
-
current
A convenient method for {@link CDI.current()}. Returns currentWeldContainerinstance if there is exactly one instance running. ThrowsIllegalStateExceptionin any other case.- Returns:
- Current
WeldContainerinstance if and only if exactly one instance exists
-
getRunningContainerIds
- Returns:
- an immutable list of ids of running containers
-
instance
Deprecated, for removal: This API element is subject to removal in a future version.Applications are encouraged to use methods for programmatic lookup directly.Deprecated -WeldContainerimplements and applications can therefore directly perform programmatic lookup from this object. SeeAbstractCDI.select(Type, Annotation...)and other methods.Provides access to all beans within the application.
- Returns:
- the instance
-
event
Provides access to all events within the application. For example:weldContainer.event().select(Bar.class).fire(new Bar());- Returns:
- the event
-
getId
Weld containers must have a unique identifier assigned when there are multiple Weld instances running at once.- Specified by:
getIdin interfaceContainerInstance- Returns:
- the container id
-
getBeanManager
public jakarta.enterprise.inject.spi.BeanManager getBeanManager()Provides direct access to the BeanManager.- Specified by:
getBeanManagerin interfaceContainerInstance- Specified by:
getBeanManagerin interfacejakarta.enterprise.inject.se.SeContainer- Specified by:
getBeanManagerin classjakarta.enterprise.inject.spi.CDI<Object>
-
shutdown
public void shutdown()Shutdown the container.- Specified by:
shutdownin interfaceContainerInstance- See Also:
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfacejakarta.enterprise.inject.se.SeContainer- Returns:
trueif the container was initialized completely and is not shut down yet,falseotherwise
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfacejakarta.enterprise.inject.se.SeContainer
-
getInstance
- Overrides:
getInstancein classorg.jboss.weld.AbstractCDI<Object>
-
checkState
protected void checkState()- Overrides:
checkStatein classorg.jboss.weld.AbstractCDI<Object>
-