Interface BeanResolutionContext

  • All Superinterfaces:
    java.lang.AutoCloseable, io.micronaut.core.value.ValueResolver<java.lang.CharSequence>
    All Known Implementing Classes:
    AbstractBeanResolutionContext, DefaultBeanResolutionContext

    @Internal
    public interface BeanResolutionContext
    extends io.micronaut.core.value.ValueResolver<java.lang.CharSequence>, java.lang.AutoCloseable
    Represents the resolution context for a current resolve of a given bean.
    Since:
    1.0
    • Method Detail

      • close

        default void close()
        Specified by:
        close in interface java.lang.AutoCloseable
      • getBean

        @NonNull
        <T> T getBean​(@NonNull
                      io.micronaut.core.type.Argument<T> beanType,
                      @Nullable
                      Qualifier<T> qualifier)
        Get a bean of the given type and qualifier.
        Type Parameters:
        T - The bean type parameter
        Parameters:
        beanType - The bean type
        qualifier - The qualifier
        Returns:
        The found bean
        Since:
        3.5.0
      • getBeansOfType

        @NonNull
        <T> java.util.Collection<T> getBeansOfType​(@NonNull
                                                   io.micronaut.core.type.Argument<T> beanType,
                                                   @Nullable
                                                   Qualifier<T> qualifier)
        Get all beans of the given type and qualifier.
        Type Parameters:
        T - The bean type parameter
        Parameters:
        beanType - The bean type
        qualifier - The qualifier
        Returns:
        The found beans
        Since:
        3.5.0
      • streamOfType

        @NonNull
        <T> java.util.stream.Stream<T> streamOfType​(@NonNull
                                                    io.micronaut.core.type.Argument<T> beanType,
                                                    @Nullable
                                                    Qualifier<T> qualifier)
        Obtains a stream of beans of the given type and qualifier.
        Type Parameters:
        T - The bean concrete type
        Parameters:
        beanType - The bean type
        qualifier - The qualifier
        Returns:
        A stream
        Since:
        3.5.0
      • findBean

        @NonNull
        <T> java.util.Optional<T> findBean​(@NonNull
                                           io.micronaut.core.type.Argument<T> beanType,
                                           @Nullable
                                           Qualifier<T> qualifier)
        Find an optional bean of the given type and qualifier.
        Type Parameters:
        T - The bean type parameter
        Parameters:
        beanType - The bean type
        qualifier - The qualifier
        Returns:
        The found bean wrapped as an Optional
        Since:
        3.5.0
      • inject

        @NonNull
        <T> T inject​(@Nullable
                     BeanDefinition<?> beanDefinition,
                     @NonNull
                     T instance)
        Injects a bean.
        Type Parameters:
        T - The instance type
        Parameters:
        beanDefinition - The requesting bean definition
        instance - The instance
        Returns:
        The instance
        Since:
        3.5.0
      • getBeanRegistrations

        @NonNull
        <T> java.util.Collection<BeanRegistration<T>> getBeanRegistrations​(@NonNull
                                                                           io.micronaut.core.type.Argument<T> beanType,
                                                                           @Nullable
                                                                           Qualifier<T> qualifier)
        Obtains the bean registrations for the given type and qualifier.
        Type Parameters:
        T - The generic type
        Parameters:
        beanType - The bean type
        qualifier - The qualifier
        Returns:
        A collection of BeanRegistration
        Since:
        3.5.0
      • destroyInjectScopedBeans

        void destroyInjectScopedBeans()
        Call back to destroy any InjectScope beans.
        Since:
        3.1.0
        See Also:
        InjectScope
      • copy

        BeanResolutionContext copy()
        Copy current context to be used later.
        Returns:
        The bean resolution context
        Since:
        3.1.0
      • getContext

        BeanContext getContext()
        Returns:
        The context
      • getRootDefinition

        BeanDefinition getRootDefinition()
        Returns:
        The class requested at the root of this resolution context
      • setAttribute

        java.lang.Object setAttribute​(java.lang.CharSequence key,
                                      java.lang.Object value)
        Store a value within the context.
        Parameters:
        key - The key
        value - The value
        Returns:
        The previous value or null
      • getAttribute

        java.lang.Object getAttribute​(java.lang.CharSequence key)
        Parameters:
        key - The key
        Returns:
        The attribute value
      • removeAttribute

        java.lang.Object removeAttribute​(java.lang.CharSequence key)
        Remove the attribute for the given key.
        Parameters:
        key - the key
        Returns:
        The previous value
      • addInFlightBean

        <T> void addInFlightBean​(BeanIdentifier beanIdentifier,
                                 BeanRegistration<T> beanRegistration)
        Adds a bean that is created as part of the resolution. This is used to store references to instances passed to BeanContext.inject(Object)
        Type Parameters:
        T - The instance type
        Parameters:
        beanIdentifier - The bean identifier
        beanRegistration - The bean registration
      • removeInFlightBean

        void removeInFlightBean​(BeanIdentifier beanIdentifier)
        Removes a bean that is in the process of being created. This is used to store references to instances passed to BeanContext.inject(Object)
        Parameters:
        beanIdentifier - The bean identifier
      • getInFlightBean

        @Nullable
        <T> BeanRegistration<T> getInFlightBean​(BeanIdentifier beanIdentifier)
        Obtains an inflight bean for the given identifier. An "In Flight" bean is one that is currently being created but has not finished construction and been registered as a singleton just yet. For example in the case whereby a bean as a PostConstruct method that also triggers bean resolution of the same bean.
        Type Parameters:
        T - The bean type
        Parameters:
        beanIdentifier - The bean identifier
        Returns:
        The bean
      • getCurrentQualifier

        @Nullable
        Qualifier<?> getCurrentQualifier()
        Returns:
        The current bean identifier
      • setCurrentQualifier

        void setCurrentQualifier​(@Nullable
                                 Qualifier<?> qualifier)
        Sets the current qualifier.
        Parameters:
        qualifier - The qualifier
      • addDependentBean

        <T> void addDependentBean​(BeanRegistration<T> beanRegistration)
        Adds a dependent bean to the resolution context.
        Type Parameters:
        T - The generic type
        Parameters:
        beanRegistration - The bean registration
      • getAndResetDependentBeans

        @NonNull
        default java.util.List<BeanRegistration<?>> getAndResetDependentBeans()
        Returns:
        The dependent beans that must be destroyed by an upstream bean
      • popDependentBeans

        @Nullable
        default java.util.List<BeanRegistration<?>> popDependentBeans()
        Returns:
        The current dependent beans that must be destroyed by an upstream bean
        Since:
        3.5.0
      • pushDependentBeans

        default void pushDependentBeans​(@Nullable
                                        java.util.List<BeanRegistration<?>> dependentBeans)
        The push the current dependent beans that must be destroyed by an upstream bean.
        Parameters:
        dependentBeans - Dependent beans collection that can be used to add more dependents
        Since:
        3.5.0
      • markDependentAsFactory

        default void markDependentAsFactory()
        Marks first dependent as factory. Dependent can be missing which means it's a singleton or scoped bean.
        Since:
        3.5.0
      • getAndResetDependentFactoryBean

        @Nullable
        default BeanRegistration<?> getAndResetDependentFactoryBean()
        Returns:
        The dependent factory beans that was used to create the bean in context
        Since:
        3.5.0