Interface SyntheticBeanCreator<T>

Type Parameters:
T - the implementation class of the synthetic bean

public interface SyntheticBeanCreator<T>
Creation function for a synthetic bean defined by SyntheticBeanBuilder. CDI container will create an instance of the creation function every time when it needs to obtain an instance of the synthetic bean. Implementations must be public classes with a public zero-parameter constructor; they must not be beans.

Starting with CDI 5.0, the create(Instance, Parameters) method is deprecated for removal; suggested replacement is create(SyntheticInjections, Parameters). Exactly one of these methods must be implemented; if not, non-portable behavior results. The CDI container must check which method exists and call it. The CDI container may assume that the create(SyntheticInjections, Parameters) method is present directly on the class registered using SyntheticBeanBuilder.createWith(Class) and not inherited from a superclass or a superinterface.

Since:
4.0
  • Method Details

    • create

      default T create(SyntheticInjections injections, Parameters params)
      Creates an instance of the synthetic bean. May only return null if the synthetic bean is @Dependent.

      The SyntheticInjections parameter may be used to simulate producer method parameter injection. All injectable references looked up from SyntheticInjections have to previously be registered using SyntheticBeanBuilder.withInjectionPoint().

      All @Dependent bean instances created by SyntheticInjections for this creation function are dependent objects of the created synthetic bean and so are destroyed when the synthetic bean instance is destroyed.

      If the synthetic bean is @Dependent, the InjectionPoint to which it is injected may be obtained from the SyntheticInjections parameter, if previously registered.

      The parameter map contains the same values that were passed to SyntheticBeanBuilder.withParam().

      Parameters:
      injections - SyntheticInjections that can be used to obtain injectable references for previously registered injection points, never null
      params - the parameter map, never null
      Returns:
      an instance of the bean, may only be null if the synthetic bean is @Dependent
      Since:
      5.0
    • create

      @Deprecated(forRemoval=true, since="5.0") default T create(Instance<Object> lookup, Parameters params)
      Deprecated, for removal: This API element is subject to removal in a future version.
      use create(SyntheticInjections, Parameters) and register all potentially looked up beans using SyntheticBeanBuilder.withInjectionPoint()
      Creates an instance of the synthetic bean. May only return null if the synthetic bean is @Dependent.

      The Instance parameter may be used to simulate producer method parameter injection. However, @Dependent bean instances obtained from the Instance during execution remain managed until the synthetic bean instance is destroyed. Therefore, implementations are encouraged to destroy unneeded @Dependent bean instances obtained from the Instance.

      If the synthetic bean is @Dependent, the InjectionPoint to which it is injected may be looked up from the Instance parameter.

      The parameter map contains the same values that were passed to SyntheticBeanBuilder.withParam().

      Parameters:
      lookup - an Instance that can be used to lookup other beans, never null
      params - the parameter map, never null
      Returns:
      an instance of the bean, may only be null if the synthetic bean is @Dependent