Interface SyntheticBeanCreator<T>
- Type Parameters:
T- the implementation class of the synthetic bean
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 Summary
Modifier and TypeMethodDescriptiondefault Tcreate(SyntheticInjections injections, Parameters params) Creates an instance of the synthetic bean.default Tcreate(Instance<Object> lookup, Parameters params) Deprecated, for removal: This API element is subject to removal in a future version.
-
Method Details
-
create
Creates an instance of the synthetic bean. May only returnnullif the synthetic bean is@Dependent.The
SyntheticInjectionsparameter may be used to simulate producer method parameter injection. All injectable references looked up fromSyntheticInjectionshave to previously be registered usingSyntheticBeanBuilder.withInjectionPoint().All
@Dependentbean instances created bySyntheticInjectionsfor 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, theInjectionPointto which it is injected may be obtained from theSyntheticInjectionsparameter, if previously registered.The parameter map contains the same values that were passed to
SyntheticBeanBuilder.withParam().- Parameters:
injections-SyntheticInjectionsthat can be used to obtain injectable references for previously registered injection points, nevernullparams- the parameter map, nevernull- Returns:
- an instance of the bean, may only be
nullif 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.usecreate(SyntheticInjections, Parameters)and register all potentially looked up beans usingSyntheticBeanBuilder.withInjectionPoint()Creates an instance of the synthetic bean. May only returnnullif the synthetic bean is@Dependent.The
Instanceparameter may be used to simulate producer method parameter injection. However,@Dependentbean instances obtained from theInstanceduring execution remain managed until the synthetic bean instance is destroyed. Therefore, implementations are encouraged to destroy unneeded@Dependentbean instances obtained from theInstance.If the synthetic bean is
@Dependent, theInjectionPointto which it is injected may be looked up from theInstanceparameter.The parameter map contains the same values that were passed to
SyntheticBeanBuilder.withParam().- Parameters:
lookup- anInstancethat can be used to lookup other beans, nevernullparams- the parameter map, nevernull- Returns:
- an instance of the bean, may only be
nullif the synthetic bean is@Dependent
-
create(SyntheticInjections, Parameters)and register all potentially looked up beans usingSyntheticBeanBuilder.withInjectionPoint()