Class BeanRegistration<T>

java.lang.Object
io.micronaut.context.BeanRegistration<T>
Type Parameters:
T - The type
All Implemented Interfaces:
CreatedBean<T>, AnnotationMetadataProvider, AnnotationSource, BeanInfo<T>, Ordered, ArgumentCoercible<T>, BeanContextConditional, BeanType<T>, Closeable, AutoCloseable

public class BeanRegistration<T> extends Object implements Ordered, CreatedBean<T>, BeanType<T>

A bean registration is an association between a BeanDefinition and a created bean, typically a Singleton.

Since:
1.0
Author:
Graeme Rocher
  • Constructor Details

    • BeanRegistration

      public BeanRegistration(BeanIdentifier identifier, BeanDefinition<T> beanDefinition, T bean)
      Parameters:
      identifier - The bean identifier
      beanDefinition - The bean definition
      bean - The bean instance
  • Method Details

    • of

      public static <K> BeanRegistration<K> of(BeanContext beanContext, BeanIdentifier identifier, BeanDefinition<K> beanDefinition, K bean)
      Creates new bean registration. Possibly disposing registration can be returned.
      Type Parameters:
      K - The bean registration type
      Parameters:
      beanContext - The bean context
      identifier - The bean identifier
      beanDefinition - The bean definition
      bean - The bean instance
      Returns:
      new bean registration
      Since:
      3.5.0
    • of

      public static <K> BeanRegistration<K> of(BeanContext beanContext, BeanIdentifier identifier, BeanDefinition<K> beanDefinition, K bean, @Nullable List<BeanRegistration<?>> dependents)
      Creates new bean registration. The returned registration's close() destroys the bean through BeanContext.destroyBean(BeanRegistration), triggering BeanPreDestroyEventListener and BeanDestroyedEventListener instances even if the bean has no destruction logic of its own.
      Type Parameters:
      K - The bean registration type
      Parameters:
      beanContext - The bean context
      identifier - The bean identifier
      beanDefinition - The bean definition
      bean - The bean instance
      dependents - The dependents
      Returns:
      new bean registration
      Since:
      3.5.0
    • getOrder

      public int getOrder()
      Specified by:
      getOrder in interface BeanInfo<T>
      Specified by:
      getOrder in interface Ordered
      Returns:
      The order of the object. Defaults to zero (no order).
    • getIdentifier

      public BeanIdentifier getIdentifier()
      Returns:
      Teh bean identifier
    • getBeanDefinition

      public BeanDefinition<T> getBeanDefinition()
      Returns:
      The bean definition
    • getBean

      public T getBean()
      Returns:
      The bean instance
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • definition

      public BeanDefinition<T> definition()
      Specified by:
      definition in interface CreatedBean<T>
      Returns:
      The bean definition.
    • bean

      public T bean()
      Specified by:
      bean in interface CreatedBean<T>
      Returns:
      The bean
    • id

      public BeanIdentifier id()
      Description copied from interface: CreatedBean
      Returns an ID that is unique to the bean and can be used to cache the instance if necessary.
      Specified by:
      id in interface CreatedBean<T>
      Returns:
      The id
    • close

      public void close()
      Description copied from interface: CreatedBean
      Destroy the bean entry, performing any shutdown and releasing any dependent objects.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface CreatedBean<T>
    • isEnabled

      public 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
    • getBeanType

      public Class<T> getBeanType()
      Description copied from interface: BeanType
      Returns the bean type.
      Specified by:
      getBeanType in interface BeanInfo<T>
      Specified by:
      getBeanType in interface BeanType<T>
      Returns:
      The underlying bean type