Package io.quarkus.arc.runtime
Interface BeanContainer
-
- All Known Implementing Classes:
BeanContainerImpl
public interface BeanContainer
Represents a CDI bean container.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
BeanContainer.Factory<T>
static interface
BeanContainer.Instance<T>
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default <T> T
beanInstance(Class<T> type, Annotation... qualifiers)
Returns a bean instance for given bean type and qualifiers.<T> BeanContainer.Factory<T>
beanInstanceFactory(Class<T> type, Annotation... qualifiers)
Returns an instance factory for given bean type and qualifiers.default <T> T
instance(Class<T> type, Annotation... qualifiers)
Deprecated.<T> BeanContainer.Factory<T>
instanceFactory(Class<T> type, Annotation... qualifiers)
Deprecated.ManagedContext
requestContext()
ManagedContext requestContext = beanContainer.requestContext(); if (requestContext.isActive()) { // Perform action } else { try { requestContext.activate(); // Perform action } finally { requestContext.terminate(); } }
-
-
-
Method Detail
-
beanInstance
default <T> T beanInstance(Class<T> type, Annotation... qualifiers)
Returns a bean instance for given bean type and qualifiers. This method follows standard CDI rules meaning that if there are two or more eligible beans, an ambiguous dependency exception is thrown. Note that the method is allowed to returnnull
if there is no matching bean which allows for fallback implementations.- Parameters:
type
-qualifiers
-- Returns:
- a bean instance or
null
if no matching bean is found
-
instance
@Deprecated default <T> T instance(Class<T> type, Annotation... qualifiers)
Deprecated.This method is deprecated and will be removed in future versions. UsebeanInstance(Class, Annotation...)
instead. As opposed tobeanInstance(Class, Annotation...)
, this method does NOT follow CDI resolution rules and in case of ambiguous resolution performs a choice based on the class type parameter.- Parameters:
type
-qualifiers
-- Returns:
- a bean instance or
null
if no matching bean is found
-
beanInstanceFactory
<T> BeanContainer.Factory<T> beanInstanceFactory(Class<T> type, Annotation... qualifiers)
Returns an instance factory for given bean type and qualifiers. This method follows standard CDI rules meaning that if there are two or more beans, an ambiguous dependency exception is thrown. Note that the factory itself is still allowed to returnnull
if there is no matching bean which allows for fallback implementations.- Parameters:
type
-qualifiers
-- Returns:
- a bean instance factory, never
null
-
instanceFactory
@Deprecated <T> BeanContainer.Factory<T> instanceFactory(Class<T> type, Annotation... qualifiers)
Deprecated.This method is deprecated and will be removed in future versions. UsebeanInstanceFactory(Class, Annotation...)
instead. As opposed tobeanInstanceFactory(Class, Annotation...)
, this method does NOT follow CDI resolution rules and in case of ambiguous resolution performs a choice based on the class type parameter.- Parameters:
type
-qualifiers
-- Returns:
- a bean instance factory, never
null
-
requestContext
ManagedContext requestContext()
ManagedContext requestContext = beanContainer.requestContext(); if (requestContext.isActive()) { // Perform action } else { try { requestContext.activate(); // Perform action } finally { requestContext.terminate(); } }
- Returns:
- the context for
RequestScoped
- Throws:
IllegalStateException
- If the container is not running
-
-