Interface RuntimeBeanDefinition.Builder<B>

Type Parameters:
B - The bean type
Enclosing interface:
RuntimeBeanDefinition<T>

public static interface RuntimeBeanDefinition.Builder<B>
A builder for constructing RuntimeBeanDefinition instances.
Since:
3.6.0
Author:
graemerocher
  • Method Details

    • qualifier

      RuntimeBeanDefinition.Builder<B> qualifier(@Nullable Qualifier<B> qualifier)
      The qualifier to use.
      Parameters:
      qualifier - The qualifier
      Returns:
      This builder
    • replaces

      RuntimeBeanDefinition.Builder<B> replaces(@Nullable Class<? extends B> otherType)
      Adds this type as a bean replacement of the given type.
      Parameters:
      otherType - The other type
      Returns:
      This bean builder
      Since:
      4.0.0
    • named

      default RuntimeBeanDefinition.Builder<B> named(@Nullable String name)
      The qualifier to use.
      Parameters:
      name - The named qualifier to use.
      Returns:
      This builder
      Since:
      3.7.0
    • scope

      RuntimeBeanDefinition.Builder<B> scope(@Nullable Class<? extends Annotation> scope)
      The scope to use.
      Parameters:
      scope - The scope
      Returns:
      This builder
    • singleton

      RuntimeBeanDefinition.Builder<B> singleton(boolean isSingleton)
      Is the bean singleton.
      Parameters:
      isSingleton - True if it is singleton
      Returns:
      This builder
    • exposedTypes

      RuntimeBeanDefinition.Builder<B> exposedTypes(Class<?>... types)
      Limit the exposed types of this bean.
      Parameters:
      types - The exposed types
      Returns:
      This builder
    • typeArguments

      RuntimeBeanDefinition.Builder<B> typeArguments(Argument<?>... arguments)
      The type arguments for the type.
      Parameters:
      arguments - The arguments
      Returns:
      This builder
    • typeArguments

      RuntimeBeanDefinition.Builder<B> typeArguments(Class<?> implementedType, Argument<?>... arguments)
      The type arguments for an implemented type of this type.
      Parameters:
      implementedType - The implemented type
      arguments - The arguments
      Returns:
      This builder
    • annotationMetadata

      RuntimeBeanDefinition.Builder<B> annotationMetadata(@Nullable AnnotationMetadata annotationMetadata)
      The annotation metadata for the bean.
      Parameters:
      annotationMetadata - The annotation metadata
      Returns:
      This builder
    • injectionPoint

      default RuntimeBeanDefinition.Builder<B> injectionPoint(Argument<?> type)
      Declares an injection point of this bean.

      The declared injection points are resolved through the resolution context of the bean creation, in the order they were declared, and are handed to the bean factory of a definition built with RuntimeBeanDefinition.builder(Argument, Function) as its RuntimeBeanDefinition.CreationContext. Resolving them this way is what makes core's own dependency handling apply to a runtime built bean: a dependent object resolved for an injection point becomes a dependent of the created bean and is destroyed with it, a circular dependency is detected, and an unsatisfied injection point fails the creation with the usual DependencyInjectionException.

      An injection point declared with a nullable argument resolves to null instead of failing when no bean is found.

      The declared injection points are also the arguments of BeanDefinition.getConstructor() and the types of BeanDefinition.getRequiredComponents(), so that the bean's dependencies can be described the way a compiled bean's are.

      Parameters:
      type - The type to inject
      Returns:
      This builder
      Since:
      5.2.0
    • injectionPoint

      RuntimeBeanDefinition.Builder<B> injectionPoint(Argument<?> type, @Nullable Qualifier<?> qualifier)
      Declares a qualified injection point of this bean.
      Parameters:
      type - The type to inject
      qualifier - The qualifier, or null for none
      Returns:
      This builder
      Since:
      5.2.0
      See Also:
    • disposer

      RuntimeBeanDefinition.Builder<B> disposer(@Nullable BiConsumer<BeanContext, B> disposer)
      The disposer to run when an instance created by this definition is destroyed.

      The disposer is invoked once per instance, after the BeanPreDestroyEventListener instances and before the BeanDestroyedEventListener instances, whenever the instance is destroyed by the BeanContext: when the BeanRegistration of a non-singleton is closed, when a singleton is destroyed through BeanContext.destroyBean(Object) or when the context itself is closed.

      A definition built with a disposer is a DisposableBeanDefinition; a definition built without one is not, so existing definitions keep their current behaviour.

      A disposer that needs to resolve beans of its own takes a RuntimeBeanDefinition.DisposalContext instead, see injectedDisposer(BiConsumer). The two forms are alternatives: setting one clears the other.

      Parameters:
      disposer - The disposer, receiving the bean context and the instance being destroyed, or null to clear a previously set disposer
      Returns:
      This builder
      Since:
      5.2.0
    • injectedDisposer

      The disposer to run when an instance created by this definition is destroyed, receiving a RuntimeBeanDefinition.DisposalContext with which it can resolve the beans it needs to do the disposal.

      It is invoked at the same point in the destruction of the instance as disposer(BiConsumer), and the two forms are alternatives: setting one clears the other.

      The lookups of the disposal context are resolved through a resolution context created for the disposal, which shares nothing with the creation of the bean being disposed of: what the disposer resolves is resolved fresh, and a dependent object among what it resolved is destroyed when the disposer returns rather than being kept for the lifetime of anything.

      Parameters:
      disposer - The disposer, receiving the disposal context and the instance being destroyed, or null to clear a previously set disposer
      Returns:
      This builder
      Since:
      5.2.0
    • build

      Builds the runtime bean.
      Returns:
      The runtime bean