Interface BeanContainer

  • All Known Implementing Classes:
    BeanContainerImpl

    public interface BeanContainer
    Represents a CDI bean container.
    • 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 return null 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. Use beanInstance(Class, Annotation...) instead.

        As opposed to beanInstance(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 return null if there is no matching bean which allows for fallback implementations.

        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