Class AbstractBeanResolutionContext

java.lang.Object
io.micronaut.context.AbstractBeanResolutionContext
All Implemented Interfaces:
BeanLocator, BeanResolutionContext, io.micronaut.core.convert.ConversionServiceProvider, io.micronaut.core.value.ValueResolver<CharSequence>, AutoCloseable
Direct Known Subclasses:
DefaultBeanResolutionContext

@Internal public abstract class AbstractBeanResolutionContext extends Object implements BeanResolutionContext
Default implementation of the BeanResolutionContext interface.
Since:
1.2.3
  • Field Details

  • Constructor Details

    • AbstractBeanResolutionContext

      @Internal protected AbstractBeanResolutionContext(DefaultBeanContext context, @Nullable BeanDefinition<?> rootDefinition)
      Parameters:
      context - The bean context
      rootDefinition - The bean root definition
  • Method Details

    • getConversionService

      public io.micronaut.core.convert.ConversionService getConversionService()
      Specified by:
      getConversionService in interface io.micronaut.core.convert.ConversionServiceProvider
    • getPropertyResolver

      public @Nullable io.micronaut.core.value.PropertyResolver getPropertyResolver()
      Specified by:
      getPropertyResolver in interface BeanResolutionContext
      Returns:
      The property resolver
    • getConfigurationPath

      public ConfigurationPath getConfigurationPath()
      Specified by:
      getConfigurationPath in interface BeanResolutionContext
      Returns:
      The configuration path.
    • setConfigurationPath

      public @Nullable ConfigurationPath setConfigurationPath(@Nullable ConfigurationPath configurationPath)
      Description copied from interface: BeanResolutionContext
      Sets the configuration path.
      Specified by:
      setConfigurationPath in interface BeanResolutionContext
      Parameters:
      configurationPath - The configuration path.
      Returns:
      The previous path
    • valueResolved

      public void valueResolved(io.micronaut.core.type.Argument<?> argument, @Nullable Qualifier<?> qualifier, String property, @Nullable Object value)
      Description copied from interface: BeanResolutionContext
      Callback when a value is resolved in some other context.
      Specified by:
      valueResolved in interface BeanResolutionContext
      Parameters:
      argument - The argument
      qualifier - The qualifier
      property - The property
      value - The value
    • resolvePropertyValue

      public @Nullable Object resolvePropertyValue(io.micronaut.core.type.Argument<?> argument, String stringValue, @Nullable String cliProperty, boolean isPlaceholder)
      Description copied from interface: BeanResolutionContext
      Resolve a property value.
      Specified by:
      resolvePropertyValue in interface BeanResolutionContext
      Parameters:
      argument - The argument
      stringValue - The string value
      cliProperty - The CLI property
      isPlaceholder - Whether it is a place holder
      Returns:
      The resolved value
    • getBean

      public <T> T getBean(io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Obtains a Bean for the given type and qualifier.
      Specified by:
      getBean in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The potentially parameterized bean type
      qualifier - The qualifier
      Returns:
      An instanceof said bean
      See Also:
    • getBean

      public <T> T getBean(Class<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Obtains a Bean for the given type and qualifier.
      Specified by:
      getBean in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      An instanceof said bean
      See Also:
    • getBean

      public <T> T getBean(BeanDefinition<T> definition)
      Description copied from interface: BeanLocator
      Obtains a Bean for the given bean definition.
      Specified by:
      getBean in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      definition - The bean type
      Returns:
      An instanceof said bean
      See Also:
    • getBeansOfType

      public <T> Collection<T> getBeansOfType(io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Get all beans of the given type.
      Specified by:
      getBeansOfType in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The potenitally parameterized bean type
      qualifier - The qualifier
      Returns:
      The found beans
    • getBeansOfType

      public <T> Collection<T> getBeansOfType(Class<T> beanType)
      Description copied from interface: BeanLocator
      Get all beans of the given type.
      Specified by:
      getBeansOfType in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      Returns:
      The found beans
    • getBeansOfType

      public <T> Collection<T> getBeansOfType(Class<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Get all beans of the given type.
      Specified by:
      getBeansOfType in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      The found beans
    • streamOfType

      public <T> Stream<T> streamOfType(io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Obtain a stream of beans of the given type.
      Specified by:
      streamOfType in interface BeanLocator
      Type Parameters:
      T - The bean concrete type
      Parameters:
      beanType - The potentially parameterized bean type
      qualifier - The qualifier
      Returns:
      A stream of instances
      See Also:
    • streamOfType

      public <T> Stream<T> streamOfType(Class<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Obtain a stream of beans of the given type.
      Specified by:
      streamOfType in interface BeanLocator
      Type Parameters:
      T - The bean concrete type
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      A stream of instances
      See Also:
    • mapOfType

      public <V> Map<String,V> mapOfType(io.micronaut.core.type.Argument<V> beanType, @Nullable Qualifier<V> qualifier)
      Description copied from interface: BeanLocator
      Obtain a map of beans of the given type where the key is the qualifier.
      Specified by:
      mapOfType in interface BeanLocator
      Type Parameters:
      V - The bean concrete type
      Parameters:
      beanType - The potentially parameterized bean type
      qualifier - The qualifier
      Returns:
      A map of instances
      See Also:
    • findBean

      public <T> Optional<T> findBean(io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Finds a Bean for the given type and qualifier.
      Specified by:
      findBean in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      An instance of Optional that is either empty or containing the specified bean
      See Also:
    • findBean

      public <T> Optional<T> findBean(Class<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Finds a Bean for the given type and qualifier.
      Specified by:
      findBean in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      An instance of Optional that is either empty or containing the specified bean
      See Also:
    • getBeansOfType

      public <T> Collection<T> getBeansOfType(io.micronaut.core.type.Argument<T> beanType)
      Description copied from interface: BeanLocator
      Get all beans of the given type.
      Specified by:
      getBeansOfType in interface BeanLocator
      Type Parameters:
      T - The bean type parameter
      Parameters:
      beanType - The potenitally parameterized bean type
      Returns:
      The found beans
    • getProxyTargetBean

      public <T> T getProxyTargetBean(Class<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanLocator
      Resolves the proxy target for a given bean type. If the bean has no proxy then the original bean is returned.
      Specified by:
      getProxyTargetBean in interface BeanLocator
      Type Parameters:
      T - The generic type
      Parameters:
      beanType - The bean type
      qualifier - The bean qualifier
      Returns:
      The proxied instance
    • getBeanRegistrations

      public <T> Collection<BeanRegistration<T>> getBeanRegistrations(io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanResolutionContext
      Obtains the bean registrations for the given type and qualifier.
      Specified by:
      getBeanRegistrations in interface BeanResolutionContext
      Type Parameters:
      T - The generic type
      Parameters:
      beanType - The bean type
      qualifier - The qualifier
      Returns:
      A collection of BeanRegistration
    • copyStateFrom

      public void copyStateFrom(AbstractBeanResolutionContext context)
      Copy the state from a previous resolution context.
      Parameters:
      context - The previous context
    • copyForLazyProxyTarget

      public BeanResolutionContext copyForLazyProxyTarget(BeanDefinition<?> proxyBeanDefinition)
      Description copied from interface: BeanResolutionContext
      Copy current context to be used later when resolving a lazy proxy target.
      Specified by:
      copyForLazyProxyTarget in interface BeanResolutionContext
      Parameters:
      proxyBeanDefinition - The proxy bean definition
      Returns:
      The bean resolution context
    • addDependentBean

      public <T> void addDependentBean(BeanRegistration<T> beanRegistration)
      Description copied from interface: BeanResolutionContext
      Adds a dependent bean to the resolution context.
      Specified by:
      addDependentBean in interface BeanResolutionContext
      Type Parameters:
      T - The generic type
      Parameters:
      beanRegistration - The bean registration
    • destroyInjectScopedBeans

      public void destroyInjectScopedBeans()
      Description copied from interface: BeanResolutionContext
      Call back to destroy any InjectScope beans.
      Specified by:
      destroyInjectScopedBeans in interface BeanResolutionContext
      See Also:
    • getAndResetDependentBeans

      public List<BeanRegistration<?>> getAndResetDependentBeans()
      Specified by:
      getAndResetDependentBeans in interface BeanResolutionContext
      Returns:
      The dependent beans that must be destroyed by an upstream bean
    • getDependentBeans

      public List<BeanRegistration<?>> getDependentBeans()
      Specified by:
      getDependentBeans in interface BeanResolutionContext
      Returns:
      The current dependent beans that must be destroyed by an upstream bean.
    • markDependentAsFactory

      public void markDependentAsFactory()
      Description copied from interface: BeanResolutionContext
      Marks first dependent as factory. Dependent can be missing which means it's a singleton or scoped bean.
      Specified by:
      markDependentAsFactory in interface BeanResolutionContext
    • getAndResetDependentFactoryBean

      public @Nullable BeanRegistration<?> getAndResetDependentFactoryBean()
      Specified by:
      getAndResetDependentFactoryBean in interface BeanResolutionContext
      Returns:
      The dependent factory beans that was used to create the bean in context
    • popDependentBeans

      public @Nullable List<BeanRegistration<?>> popDependentBeans()
      Specified by:
      popDependentBeans in interface BeanResolutionContext
      Returns:
      The current dependent beans that must be destroyed by an upstream bean
    • pushDependentBeans

      public void pushDependentBeans(@Nullable List<BeanRegistration<?>> dependentBeans)
      Description copied from interface: BeanResolutionContext
      The push the current dependent beans that must be destroyed by an upstream bean.
      Specified by:
      pushDependentBeans in interface BeanResolutionContext
      Parameters:
      dependentBeans - Dependent beans collection that can be used to add more dependents
    • getContext

      public final BeanContext getContext()
      Specified by:
      getContext in interface BeanResolutionContext
      Returns:
      The context
    • getRootDefinition

      public final @Nullable BeanDefinition getRootDefinition()
      Specified by:
      getRootDefinition in interface BeanResolutionContext
      Returns:
      The class requested at the root of this resolution context
    • getPath

      public final BeanResolutionContext.Path getPath()
      Specified by:
      getPath in interface BeanResolutionContext
      Returns:
      The path that this resolution has taken so far
    • setAttribute

      public final Object setAttribute(CharSequence key, @Nullable Object value)
      Description copied from interface: BeanResolutionContext
      Store a value within the context.
      Specified by:
      setAttribute in interface BeanResolutionContext
      Parameters:
      key - The key
      value - The value
      Returns:
      The previous value or null
    • getAttribute

      public final @Nullable Object getAttribute(CharSequence key)
      Specified by:
      getAttribute in interface BeanResolutionContext
      Parameters:
      key - The key
      Returns:
      The attribute value
    • removeAttribute

      public final @Nullable Object removeAttribute(CharSequence key)
      Description copied from interface: BeanResolutionContext
      Remove the attribute for the given key.
      Specified by:
      removeAttribute in interface BeanResolutionContext
      Parameters:
      key - the key
      Returns:
      The previous value
    • getAttributes

      public @Nullable Map<CharSequence, Object> getAttributes()
      Description copied from interface: BeanResolutionContext
      Get the map representing current attributes.
      Specified by:
      getAttributes in interface BeanResolutionContext
      Returns:
      All attributes
    • setAttributes

      public void setAttributes(@Nullable Map<CharSequence, Object> attributes)
      Description copied from interface: BeanResolutionContext
      Set new attributes map (The map is supposed to be mutable).
      Specified by:
      setAttributes in interface BeanResolutionContext
      Parameters:
      attributes - The attributes
    • getCurrentQualifier

      public @Nullable Qualifier<?> getCurrentQualifier()
      Specified by:
      getCurrentQualifier in interface BeanResolutionContext
      Returns:
      The current bean identifier
    • setCurrentQualifier

      public void setCurrentQualifier(@Nullable Qualifier<?> qualifier)
      Description copied from interface: BeanResolutionContext
      Sets the current qualifier.
      Specified by:
      setCurrentQualifier in interface BeanResolutionContext
      Parameters:
      qualifier - The qualifier
    • get

      public <T> Optional<T> get(CharSequence name, io.micronaut.core.convert.ArgumentConversionContext<T> conversionContext)
      Specified by:
      get in interface io.micronaut.core.value.ValueResolver<CharSequence>
    • get

      public <T> Optional<T> get(CharSequence name, Class<T> requiredType)
      Specified by:
      get in interface io.micronaut.core.value.ValueResolver<CharSequence>
    • findBeanDefinitions

      public final <T> Collection<BeanDefinition<T>> findBeanDefinitions(io.micronaut.core.type.Argument<T> argument, @Nullable BeanDefinition<?> bd)
    • getBeanRegistration

      public final <T> BeanRegistration<T> getBeanRegistration(io.micronaut.core.type.Argument<T> argument, @Nullable Qualifier<T> qualifier)
    • getProxyTargetBean

      public <T> T getProxyTargetBean(BeanDefinition<T> definition, io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
      Description copied from interface: BeanResolutionContext
      Resolves the proxy target for a given proxy bean definition. If the bean has no proxy then the original bean is returned.
      Specified by:
      getProxyTargetBean in interface BeanResolutionContext
      Type Parameters:
      T - The generic type
      Parameters:
      definition - The proxy bean definition
      beanType - The bean type
      qualifier - The bean qualifier
      Returns:
      The proxied instance