Interface RuntimeBeanDefinition.CreationContext

All Superinterfaces:
RuntimeBeanDefinition.LookupContext
Enclosing interface:
RuntimeBeanDefinition<T>

public static interface RuntimeBeanDefinition.CreationContext extends RuntimeBeanDefinition.LookupContext
The context of a single creation of a bean built at runtime, passed to the bean factory of a definition built with RuntimeBeanDefinition.builder(Argument, Function).

It carries the beans resolved for the injection points the definition declared with RuntimeBeanDefinition.Builder.injectionPoint(Argument), the injection point the bean is being created for, and the lookups of RuntimeBeanDefinition.LookupContext for anything the definition could not declare up front.

The injected beans were resolved through the resolution context of this creation, so any of them that is a dependent object (a @Prototype or @Dependent bean, for example) is a dependent of the created bean and is destroyed with it. A bean the factory looks up itself with RuntimeBeanDefinition.LookupContext.getBean(Argument) is resolved through the same resolution context and has the same lifetime; the difference between the two is only that a declared injection point is described by the definition and resolved before the factory runs, while a lookup is decided by the factory as it runs. The exception is a bean obtained from BeanContext.createBean(Class), which records no dependents for any bean, runtime built or compiled.

Since:
5.2.0
Author:
graemerocher
  • Method Details

    • getInjectionPoint

      Optional<InjectionPoint<?>> getInjectionPoint()
      The injection point the bean is being created for.

      For a constructor or method argument this is an ArgumentInjectionPoint, which exposes the argument and the bean that declares it. It is empty when the bean is not being created for an injection point, as it is for a direct BeanLocator.getBean(Class) lookup.

      Returns:
      The injection point, or empty if there is none
    • getInjectedBeanCount

      int getInjectedBeanCount()
      Returns:
      The number of injection points the definition declared
    • getInjectedBean

      <V> @Nullable V getInjectedBean(int index)
      The bean resolved for the injection point at the given index, in the order the injection points were declared on the builder.
      Type Parameters:
      V - The injected type
      Parameters:
      index - The index
      Returns:
      The resolved bean, which is null only when the injection point was declared with a nullable argument and no bean was found
      Throws:
      IndexOutOfBoundsException - If the index is out of range
    • getInjectedBean

      default <V> @Nullable V getInjectedBean(Argument<V> type)
      The bean resolved for the injection point declared with the given type and no qualifier.
      Type Parameters:
      V - The injected type
      Parameters:
      type - The type the injection point was declared with
      Returns:
      The resolved bean, which is null only when the injection point was declared with a nullable argument and no bean was found
      Throws:
      IllegalArgumentException - If no such injection point was declared
    • getInjectedBean

      <V> @Nullable V getInjectedBean(Argument<V> type, @Nullable Qualifier<V> qualifier)
      The bean resolved for the injection point declared with the given type and qualifier.
      Type Parameters:
      V - The injected type
      Parameters:
      type - The type the injection point was declared with
      qualifier - The qualifier the injection point was declared with
      Returns:
      The resolved bean, which is null only when the injection point was declared with a nullable argument and no bean was found
      Throws:
      IllegalArgumentException - If no such injection point was declared