Interface BeanConfigurator<T>

  • Type Parameters:
    T - the class of the bean instance

    public interface BeanConfigurator<T>
    This API is an helper to configure a new Bean instance. CDI container must provides an implementation of this interface. This builder is not thread safe and shall not be used concurrently.

    CDI Lite implementations are not required to provide support for Portable Extensions.

    Since:
    2.0
    Author:
    Martin Kouba, Antoine Sabot-Durand
    See Also:
    AfterBeanDiscovery.addBean()
    • Method Detail

      • beanClass

        BeanConfigurator<T> beanClass​(Class<?> beanClass)
        Set the class of the configured Bean. If not set, the extension class is used.
        Parameters:
        beanClass - class of the configured bean
        Returns:
        self
      • addInjectionPoint

        BeanConfigurator<T> addInjectionPoint​(InjectionPoint injectionPoint)
        Add an InjectionPoint to the configured bean
        Parameters:
        injectionPoint - the injectionPoint to add
        Returns:
        self
      • addInjectionPoints

        BeanConfigurator<T> addInjectionPoints​(InjectionPoint... injectionPoints)
        Add InjectionPoints to the configured bean
        Parameters:
        injectionPoints - the injectionPoints to add
        Returns:
        self
      • addInjectionPoints

        BeanConfigurator<T> addInjectionPoints​(Set<InjectionPoint> injectionPoints)
        Add InjectionPoints to the configured bean
        Parameters:
        injectionPoints - the injectionPoints to add
        Returns:
        self
      • injectionPoints

        BeanConfigurator<T> injectionPoints​(InjectionPoint... injectionPoints)
        Replace InjectionPoints for the configured bean
        Parameters:
        injectionPoints - the injectionPoints for the configured bean
        Returns:
        self
      • injectionPoints

        BeanConfigurator<T> injectionPoints​(Set<InjectionPoint> injectionPoints)
        Replace InjectionPoints for the configured bean
        Parameters:
        injectionPoints - the injectionPoints for the configured bean
        Returns:
        self
      • produceWith

        <U extends TBeanConfigurator<U> produceWith​(Function<Instance<Object>,​U> callback)
        Set a callback to create a bean instance.

        The Instance argument might be used to simulate producer method parameter injection. However, dependent scoped bean instances obtained from Instance during the callback execution remain managed until the produced bean instance is destroyed. Therefore, applications are encouraged to always destroy unneeded dependent scoped bean instances obtained from Instance.

        Type Parameters:
        U - instance type
        Parameters:
        callback - the callback to create the instance
        Returns:
        self
      • destroyWith

        BeanConfigurator<T> destroyWith​(BiConsumer<T,​CreationalContext<T>> callback)
        Set a callback to destroy a bean instance.

        If no destroy callback is specified, a NOOP callback is automatically set.

        Parameters:
        callback - the callback to destroy the instance
        Returns:
        self
      • disposeWith

        BeanConfigurator<T> disposeWith​(BiConsumer<T,​Instance<Object>> callback)
        Set a callback to destroy a bean instance.

        If no dispose callback is specified, a NOOP callback is automatically set.

        The Instance argument might be used to simulate disposer method parameter injection. All dependent scoped bean instances obtained from Instance during the callback execution are destroyed when the execution completes.

        Parameters:
        callback - the callback to dispose the instance
        Returns:
        self
      • read

        <U extends TBeanConfigurator<U> read​(AnnotatedType<U> type)
        Read the information from the given annotated type. All relevant information is overwritten.
        Type Parameters:
        U - instance type
        Parameters:
        type - class to read information from
        Returns:
        self
      • read

        BeanConfigurator<T> read​(BeanAttributes<?> beanAttributes)
        Read the information from the given bean attributes. All relevant information is overwritten.
        Parameters:
        beanAttributes - beanAttributes to read information from
        Returns:
        self
      • addType

        BeanConfigurator<T> addType​(Type type)
        Add a type to the bean types
        Parameters:
        type - the type to add
        Returns:
        self
      • addType

        BeanConfigurator<T> addType​(TypeLiteral<?> typeLiteral)
        Add a type to the bean types
        Parameters:
        typeLiteral - the type to add
        Returns:
        self
      • addTypes

        BeanConfigurator<T> addTypes​(Type... types)
        Add types to the bean types
        Parameters:
        types - types to add
        Returns:
        self
      • addTypes

        BeanConfigurator<T> addTypes​(Set<Type> types)
        Add types to the bean types
        Parameters:
        types - types to add
        Returns:
        self
      • addTransitiveTypeClosure

        BeanConfigurator<T> addTransitiveTypeClosure​(Type type)
        Adds an unrestricted set of bean types for the given type as if it represented a bean class of a managed bean. Illegal bean types are omitted.
        Parameters:
        type - to build the closure from
        Returns:
        self
      • types

        BeanConfigurator<T> types​(Type... types)
        Replace bean types
        Parameters:
        types - the types of the configured bean
        Returns:
        self
      • types

        BeanConfigurator<T> types​(Set<Type> types)
        Replace bean types
        Parameters:
        types - the types of the configured bean
        Returns:
        self
      • scope

        BeanConfigurator<T> scope​(Class<? extends Annotation> scope)
        Replace Bean scope
        Parameters:
        scope - new scope for the configured bean
        Returns:
        self
      • addQualifier

        BeanConfigurator<T> addQualifier​(Annotation qualifier)
        Add a qualifier to the configured bean
        Parameters:
        qualifier - qualifier to add
        Returns:
        self
      • addQualifiers

        BeanConfigurator<T> addQualifiers​(Annotation... qualifiers)
        Add qualifiers to the bean.
        Parameters:
        qualifiers - qualifiers to add
        Returns:
        self
      • addQualifiers

        BeanConfigurator<T> addQualifiers​(Set<Annotation> qualifiers)
        Add qualifiers to the bean.
        Parameters:
        qualifiers - qualifiers to add
        Returns:
        self
      • qualifiers

        BeanConfigurator<T> qualifiers​(Annotation... qualifiers)
        Replace all qualifiers.
        Parameters:
        qualifiers - qualifiers for the build bean
        Returns:
        self
      • qualifiers

        BeanConfigurator<T> qualifiers​(Set<Annotation> qualifiers)
        Replace all qualifiers.
        Parameters:
        qualifiers - for the configured bean
        Returns:
        self
      • addStereotype

        BeanConfigurator<T> addStereotype​(Class<? extends Annotation> stereotype)
        Add a stereotype to the configured bean
        Parameters:
        stereotype - stereotype to add
        Returns:
        self
      • addStereotypes

        BeanConfigurator<T> addStereotypes​(Set<Class<? extends Annotation>> stereotypes)
        Add stereotypes to the configured bean
        Parameters:
        stereotypes - stereotypes to add
        Returns:
        self
      • stereotypes

        BeanConfigurator<T> stereotypes​(Set<Class<? extends Annotation>> stereotypes)
        Replace stereotypes on the configured bean
        Parameters:
        stereotypes - for the configured bean
        Returns:
        self
      • name

        BeanConfigurator<T> name​(String name)
        Set the name of the configured bean
        Parameters:
        name - name for the configured bean
        Returns:
        self
      • alternative

        BeanConfigurator<T> alternative​(boolean value)
        Change the alternative status of the configured bean. By default the configured bean is not an alternative.
        Parameters:
        value - value for alternative property
        Returns:
        self
      • priority

        BeanConfigurator<T> priority​(int priority)
        Set the priority of the configured bean. By default, the configured bean does not have a priority.

        This is equivalent to putting the Priority annotation to an actual bean class or making a custom Bean class implement Prioritized.

        This method has no effect if the configured bean is not an alternative.

        Parameters:
        priority - the priority value
        Returns:
        self