Interface RuntimeBeanDefinition<T>

Type Parameters:
T - The bean type
All Superinterfaces:
io.micronaut.core.annotation.AnnotationMetadata, io.micronaut.core.annotation.AnnotationMetadataDelegate, io.micronaut.core.annotation.AnnotationMetadataProvider, io.micronaut.core.annotation.AnnotationSource, io.micronaut.core.type.ArgumentCoercible<T>, BeanContextConditional, BeanDefinition<T>, BeanDefinitionReference<T>, io.micronaut.core.beans.BeanInfo<T>, BeanType<T>, InstantiatableBeanDefinition<T>, io.micronaut.core.naming.Named, io.micronaut.core.order.Ordered, QualifiedBeanType<T>

public interface RuntimeBeanDefinition<T> extends BeanDefinitionReference<T>, InstantiatableBeanDefinition<T>, BeanContextConditional
Allow the construction for bean definitions programmatically that can be registered via BeanDefinitionRegistry at runtime.

This differs from BeanDefinitionRegistry.registerSingleton(Object) in that beans registered this way can be created lazily or not at all and participate more completely in the life cycle of the BeanContext (for examples event listeners like BeanCreatedEventListener will be fired).

Note that it is generally not recommended to use this approach and build time bean computation is preferred. This type is designed to support a few limited use cases where runtime bean registration is required.

Since:
3.6.0
See Also:
  • Method Details

    • getAnnotationMetadata

      default io.micronaut.core.annotation.AnnotationMetadata getAnnotationMetadata()
      Specified by:
      getAnnotationMetadata in interface io.micronaut.core.annotation.AnnotationMetadataProvider
    • isEnabled

      default boolean isEnabled(BeanContext context, @Nullable BeanResolutionContext resolutionContext)
      Description copied from interface: BeanContextConditional
      Return whether this component is enabled for the given context.
      Specified by:
      isEnabled in interface BeanContextConditional
      Parameters:
      context - The context
      resolutionContext - The bean resolution context
      Returns:
      True if it is
    • getTypeArguments

      default List<io.micronaut.core.type.Argument<?>> getTypeArguments(Class<?> type)
      Description copied from interface: BeanDefinition
      Return the type arguments for the given interface or super type for this bean.
      Specified by:
      getTypeArguments in interface BeanDefinition<T>
      Parameters:
      type - The super class or interface type
      Returns:
      The type arguments
    • isContextScope

      default boolean isContextScope()
      Specified by:
      isContextScope in interface BeanDefinitionReference<T>
      Returns:
      Is this class context scope
    • isConfigurationProperties

      default boolean isConfigurationProperties()
      Specified by:
      isConfigurationProperties in interface BeanDefinition<T>
      Specified by:
      isConfigurationProperties in interface BeanDefinitionReference<T>
      Returns:
      Is this bean a configuration properties.
    • load

      default BeanDefinition<T> load()
      Description copied from interface: BeanDefinitionReference
      Loads the bean definition.
      Specified by:
      load in interface BeanDefinitionReference<T>
      Returns:
      The loaded component definition or null if it shouldn't be loaded
    • getBeanDefinitionName

      default String getBeanDefinitionName()
      Specified by:
      getBeanDefinitionName in interface BeanDefinitionReference<T>
      Returns:
      The class name of the backing BeanDefinition
    • load

      default BeanDefinition<T> load(BeanContext context)
      Description copied from interface: BeanDefinitionReference
      Loads the bean definition for the current BeanContext.
      Specified by:
      load in interface BeanDefinitionReference<T>
      Parameters:
      context - The bean context
      Returns:
      The loaded bean definition or null if it shouldn't be loaded
    • isPresent

      default boolean isPresent()
      Specified by:
      isPresent in interface BeanDefinitionReference<T>
      Returns:
      Is the underlying bean type present on the classpath
    • isSingleton

      default boolean isSingleton()
      Specified by:
      isSingleton in interface BeanDefinition<T>
      Specified by:
      isSingleton in interface BeanDefinitionReference<T>
      Returns:
      Is this bean a singleton.
    • of

      static <B> RuntimeBeanDefinition<B> of(B bean)
      Creates a new effectively singleton bean definition that references the given bean.
      Type Parameters:
      B - The bean type
      Parameters:
      bean - The bean
      Returns:
      The BeanDefinitionReference
      Since:
      3.6.0
    • of

      static <B> RuntimeBeanDefinition<B> of(Class<B> beanType, Supplier<B> beanSupplier)
      Creates a new bean definition that will resolve the bean from the given supplier.

      The bean is by default not singleton and the supplier will be invoked for each injection point.

      Type Parameters:
      B - The bean type
      Parameters:
      beanType - The bean type
      beanSupplier - The bean supplier
      Returns:
      The BeanDefinitionReference
      Since:
      3.6.0
    • builder

      static <B> RuntimeBeanDefinition.Builder<B> builder(B bean)
      A new builder for constructing and configuring runtime created beans.
      Type Parameters:
      B - The bean type
      Parameters:
      bean - The bean to use
      Returns:
      The builder
    • builder

      static <B> RuntimeBeanDefinition.Builder<B> builder(Class<B> beanType, Supplier<B> beanSupplier)
      A new builder for constructing and configuring runtime created beans.
      Type Parameters:
      B - The bean type
      Parameters:
      beanType - The bean type
      beanSupplier - The bean supplier
      Returns:
      The builder
    • builder

      static <B> RuntimeBeanDefinition.Builder<B> builder(io.micronaut.core.type.Argument<B> beanType, Supplier<B> beanSupplier)
      A new builder for constructing and configuring runtime created beans.
      Type Parameters:
      B - The bean type
      Parameters:
      beanType - The bean type
      beanSupplier - The bean supplier
      Returns:
      The builder