Interface BeanContainer

All Known Implementing Classes:
BeanContainerImpl

public interface BeanContainer
Represents a CDI bean container.

Extensions using this API can also leverage arbitrary methods from running ArcContainer which can be obtained by invoking a static method Arc.container().

  • Method Details

    • beanInstance

      <T> T beanInstance(Class<T> beanType, Annotation... beanQualifiers)
      Resolves a bean instance for given bean type and qualifiers.

      Performs standard CDI resolution meaning it either returns a bean instance or throws a corresponding exception if the dependency is either unsatisfied or ambiguous.

      Parameters:
      beanType - type of the bean
      beanQualifiers - bean qualifiers
      Returns:
      a bean instance; never null
    • beanInstanceFactory

      <T> BeanContainer.Factory<T> beanInstanceFactory(Class<T> type, Annotation... qualifiers)
      Returns an instance factory for given bean type and qualifiers.

      This method performs CDI ambiguous dependency resolution and throws and exception if there are two or more beans with given type and qualifiers.

      If no matching bean is found, uses a default fallback factory that will attempt to instantiate a non-CDI object of the given class via no-args constructor.

      If you need custom factory behavior, take a look at beanInstanceFactory(Supplier, Class, Annotation...)

      Parameters:
      type - bean type
      qualifiers - bean qualifiers
      Returns:
      a bean instance factory, never null
    • beanInstanceFactory

      <T> BeanContainer.Factory<T> beanInstanceFactory(Supplier<BeanContainer.Factory<T>> fallbackSupplier, Class<T> type, Annotation... qualifiers)
      Returns an instance factory for given bean type and qualifiers.

      This method performs CDI ambiguous dependency resolution and throws and exception if there are two or more beans with given type and qualifiers.

      If no matching bean is found, delegates all calls to the supplied factory fallback.

      Parameters:
      fallbackSupplier - supplier to delegate to if there is no bean
      type - bean type
      qualifiers - bean qualifiers
      Returns:
      a bean instance factory, never null
    • requestContext

      io.quarkus.arc.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