Interface RuntimeBeanDefinition.LookupContext

All Known Subinterfaces:
RuntimeBeanDefinition.CreationContext, RuntimeBeanDefinition.DisposalContext
Enclosing interface:
RuntimeBeanDefinition<T>

public static interface RuntimeBeanDefinition.LookupContext
The lookups a runtime built bean can perform while it is being created or disposed of.

Every lookup here is resolved through the BeanResolutionContext of the creation or of the disposal, which is what makes core's own dependency handling apply to it: a dependent object (a @Prototype or @Dependent bean, for example) that a lookup resolves becomes a dependent of that creation or disposal and is destroyed with it, a circular dependency is detected, and an unsatisfied getBean(Argument) fails with the usual DependencyInjectionException. Resolving the same bean from getBeanContext() instead resolves it outside that context, where none of that applies.

How long what a lookup resolves lives is decided by the context it was made from: a dependent resolved from a RuntimeBeanDefinition.CreationContext is destroyed when the created bean is, and one resolved from a RuntimeBeanDefinition.DisposalContext is destroyed when the disposer returns.

Since:
5.2.0
Author:
graemerocher
  • Method Details

    • getBeanContext

      BeanContext getBeanContext()
      Returns:
      The bean context the bean belongs to
    • getBean

      default <V> V getBean(Argument<V> type)
      Looks up a bean of the given type.
      Type Parameters:
      V - The looked up type
      Parameters:
      type - The type to look up
      Returns:
      The bean, never null
      Throws:
      DependencyInjectionException - If no bean of the type exists
    • getBean

      <V> V getBean(Argument<V> type, @Nullable Qualifier<V> qualifier)
      Looks up a bean of the given type and qualifier.
      Type Parameters:
      V - The looked up type
      Parameters:
      type - The type to look up
      qualifier - The qualifier, or null for none
      Returns:
      The bean, never null
      Throws:
      DependencyInjectionException - If no such bean exists
    • findBean

      default <V> Optional<V> findBean(Argument<V> type)
      Looks up a bean of the given type if one exists.
      Type Parameters:
      V - The looked up type
      Parameters:
      type - The type to look up
      Returns:
      The bean, or empty if none exists
    • findBean

      <V> Optional<V> findBean(Argument<V> type, @Nullable Qualifier<V> qualifier)
      Looks up a bean of the given type and qualifier if one exists.
      Type Parameters:
      V - The looked up type
      Parameters:
      type - The type to look up
      qualifier - The qualifier, or null for none
      Returns:
      The bean, or empty if none exists
    • getBeansOfType

      default <V> Collection<V> getBeansOfType(Argument<V> type)
      Looks up all the beans of the given type.
      Type Parameters:
      V - The looked up type
      Parameters:
      type - The type to look up
      Returns:
      The beans, empty if there are none
    • getBeansOfType

      <V> Collection<V> getBeansOfType(Argument<V> type, @Nullable Qualifier<V> qualifier)
      Looks up all the beans of the given type and qualifier.
      Type Parameters:
      V - The looked up type
      Parameters:
      type - The type to look up
      qualifier - The qualifier, or null for none
      Returns:
      The beans, empty if there are none