Interface SyntheticBeanDisposer<T>

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

public interface SyntheticBeanDisposer<T>
Destruction function for a synthetic bean defined by SyntheticBeanBuilder. CDI container will create an instance of the destruction function every time when it needs to destroy 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 dispose(Object, Instance, Parameters) method is deprecated for removal; suggested replacement is dispose(Object, 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 dispose(Object, SyntheticInjections, Parameters) method is present directly on the class registered using SyntheticBeanBuilder.disposeWith(Class) and not inherited from a superclass or a superinterface.

Since:
4.0
  • Method Details

    • dispose

      default void dispose(T instance, SyntheticInjections injections, Parameters params)
      Destroys an instance of the synthetic bean.

      The SyntheticInjections parameter may be used to simulate disposer 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 destruction function are destroyed when the dispose() invocation completes.

      Trying to look up InjectionPoint from the SyntheticInjections parameter is invalid.

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

      Parameters:
      instance - the synthetic bean instance, never null
      injections - SyntheticInjections that can be used to obtain injectable references for previously registered injection points, never null
      params - the parameter map, never null
      Since:
      5.0
    • dispose

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

      The Instance parameter may be used to simulate disposer method parameter injection. All @Dependent bean instances obtained from the Instance during execution are destroyed when execution completes.

      Trying to look up InjectionPoint from the Instance parameter is invalid.

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

      Parameters:
      instance - the synthetic bean instance, never null
      lookup - an Instance that can be used to lookup other beans, never null
      params - the parameter map, never null