Package io.micronaut.context
Class AbstractBeanResolutionContext
- java.lang.Object
-
- io.micronaut.context.AbstractBeanResolutionContext
-
- All Implemented Interfaces:
BeanResolutionContext
,io.micronaut.core.value.ValueResolver<java.lang.CharSequence>
,java.lang.AutoCloseable
- Direct Known Subclasses:
DefaultBeanResolutionContext
@Internal public abstract class AbstractBeanResolutionContext extends java.lang.Object implements BeanResolutionContext
Default implementation of theBeanResolutionContext
interface.- Since:
- 1.2.3
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractBeanResolutionContext.AnnotationSegment
A segment that represents annotation.static class
AbstractBeanResolutionContext.ConstructorArgumentSegment
A segment that represents a method argument.static class
AbstractBeanResolutionContext.ConstructorSegment
A segment that represents a constructor.static class
AbstractBeanResolutionContext.FieldSegment
A segment that represents a field.static class
AbstractBeanResolutionContext.MethodArgumentSegment
A segment that represents a method argument.static class
AbstractBeanResolutionContext.MethodSegment
A segment that represents a method.-
Nested classes/interfaces inherited from interface io.micronaut.context.BeanResolutionContext
BeanResolutionContext.Path, BeanResolutionContext.Segment<T>
-
-
Field Summary
Fields Modifier and Type Field Description protected DefaultBeanContext
context
protected BeanResolutionContext.Path
path
protected BeanDefinition<?>
rootDefinition
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractBeanResolutionContext(DefaultBeanContext context, BeanDefinition<?> rootDefinition)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> void
addDependentBean(BeanRegistration<T> beanRegistration)
Adds a dependent bean to the resolution context.void
copyStateFrom(AbstractBeanResolutionContext context)
Copy the state from a previous resolution context.void
destroyInjectScopedBeans()
Call back to destroy anyInjectScope
beans.<T> java.util.Optional<T>
findBean(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Find an optional bean of the given type and qualifier.<T> java.util.Optional<T>
get(java.lang.CharSequence name, io.micronaut.core.convert.ArgumentConversionContext<T> conversionContext)
<T> java.util.Optional<T>
get(java.lang.CharSequence name, java.lang.Class<T> requiredType)
java.util.List<BeanRegistration<?>>
getAndResetDependentBeans()
BeanRegistration<?>
getAndResetDependentFactoryBean()
java.lang.Object
getAttribute(java.lang.CharSequence key)
<T> T
getBean(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Get a bean of the given type and qualifier.<T> java.util.Collection<BeanRegistration<T>>
getBeanRegistrations(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Obtains the bean registrations for the given type and qualifier.<T> java.util.Collection<T>
getBeansOfType(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Get all beans of the given type and qualifier.BeanContext
getContext()
Qualifier<?>
getCurrentQualifier()
BeanResolutionContext.Path
getPath()
BeanDefinition
getRootDefinition()
<T> T
inject(BeanDefinition<?> beanDefinition, T instance)
Injects a bean.void
markDependentAsFactory()
Marks first dependent as factory.protected void
onNewSegment(BeanResolutionContext.Segment<?> segment)
java.util.List<BeanRegistration<?>>
popDependentBeans()
void
pushDependentBeans(java.util.List<BeanRegistration<?>> dependentBeans)
The push the current dependent beans that must be destroyed by an upstream bean.java.lang.Object
removeAttribute(java.lang.CharSequence key)
Remove the attribute for the given key.java.lang.Object
setAttribute(java.lang.CharSequence key, java.lang.Object value)
Store a value within the context.void
setCurrentQualifier(Qualifier<?> qualifier)
Sets the current qualifier.<T> java.util.stream.Stream<T>
streamOfType(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Obtains a stream of beans of the given type and qualifier.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.micronaut.context.BeanResolutionContext
addInFlightBean, close, copy, getInFlightBean, removeInFlightBean
-
-
-
-
Field Detail
-
context
protected final DefaultBeanContext context
-
rootDefinition
protected final BeanDefinition<?> rootDefinition
-
path
protected final BeanResolutionContext.Path path
-
-
Constructor Detail
-
AbstractBeanResolutionContext
@Internal protected AbstractBeanResolutionContext(DefaultBeanContext context, BeanDefinition<?> rootDefinition)
- Parameters:
context
- The bean contextrootDefinition
- The bean root definition
-
-
Method Detail
-
getBean
@NonNull public <T> T getBean(@NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Description copied from interface:BeanResolutionContext
Get a bean of the given type and qualifier.- Specified by:
getBean
in interfaceBeanResolutionContext
- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- The found bean
-
getBeansOfType
@NonNull public <T> java.util.Collection<T> getBeansOfType(@NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Description copied from interface:BeanResolutionContext
Get all beans of the given type and qualifier.- Specified by:
getBeansOfType
in interfaceBeanResolutionContext
- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- The found beans
-
streamOfType
@NonNull public <T> java.util.stream.Stream<T> streamOfType(@NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Description copied from interface:BeanResolutionContext
Obtains a stream of beans of the given type and qualifier.- Specified by:
streamOfType
in interfaceBeanResolutionContext
- Type Parameters:
T
- The bean concrete type- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- A stream
-
findBean
@NonNull public <T> java.util.Optional<T> findBean(@NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Description copied from interface:BeanResolutionContext
Find an optional bean of the given type and qualifier.- Specified by:
findBean
in interfaceBeanResolutionContext
- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- The found bean wrapped as an
Optional
-
inject
@NonNull public <T> T inject(@Nullable BeanDefinition<?> beanDefinition, @NonNull T instance)
Description copied from interface:BeanResolutionContext
Injects a bean.- Specified by:
inject
in interfaceBeanResolutionContext
- Type Parameters:
T
- The instance type- Parameters:
beanDefinition
- The requesting bean definitioninstance
- The instance- Returns:
- The instance
-
getBeanRegistrations
@NonNull public <T> java.util.Collection<BeanRegistration<T>> getBeanRegistrations(@NonNull 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 interfaceBeanResolutionContext
- Type Parameters:
T
- The generic type- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- A collection of
BeanRegistration
-
copyStateFrom
public void copyStateFrom(@NonNull AbstractBeanResolutionContext context)
Copy the state from a previous resolution context.- Parameters:
context
- The previous 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 interfaceBeanResolutionContext
- Type Parameters:
T
- The generic type- Parameters:
beanRegistration
- The bean registration
-
destroyInjectScopedBeans
public void destroyInjectScopedBeans()
Description copied from interface:BeanResolutionContext
Call back to destroy anyInjectScope
beans.- Specified by:
destroyInjectScopedBeans
in interfaceBeanResolutionContext
- See Also:
InjectScope
-
getAndResetDependentBeans
@NonNull public java.util.List<BeanRegistration<?>> getAndResetDependentBeans()
- Specified by:
getAndResetDependentBeans
in interfaceBeanResolutionContext
- Returns:
- The 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 interfaceBeanResolutionContext
-
getAndResetDependentFactoryBean
public BeanRegistration<?> getAndResetDependentFactoryBean()
- Specified by:
getAndResetDependentFactoryBean
in interfaceBeanResolutionContext
- Returns:
- The dependent factory beans that was used to create the bean in context
-
popDependentBeans
public java.util.List<BeanRegistration<?>> popDependentBeans()
- Specified by:
popDependentBeans
in interfaceBeanResolutionContext
- Returns:
- The current dependent beans that must be destroyed by an upstream bean
-
pushDependentBeans
public void pushDependentBeans(java.util.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 interfaceBeanResolutionContext
- Parameters:
dependentBeans
- Dependent beans collection that can be used to add more dependents
-
getContext
public final BeanContext getContext()
- Specified by:
getContext
in interfaceBeanResolutionContext
- Returns:
- The context
-
getRootDefinition
public final BeanDefinition getRootDefinition()
- Specified by:
getRootDefinition
in interfaceBeanResolutionContext
- Returns:
- The class requested at the root of this resolution context
-
getPath
public final BeanResolutionContext.Path getPath()
- Specified by:
getPath
in interfaceBeanResolutionContext
- Returns:
- The path that this resolution has taken so far
-
setAttribute
public final java.lang.Object setAttribute(java.lang.CharSequence key, java.lang.Object value)
Description copied from interface:BeanResolutionContext
Store a value within the context.- Specified by:
setAttribute
in interfaceBeanResolutionContext
- Parameters:
key
- The keyvalue
- The value- Returns:
- The previous value or null
-
getAttribute
public final java.lang.Object getAttribute(java.lang.CharSequence key)
- Specified by:
getAttribute
in interfaceBeanResolutionContext
- Parameters:
key
- The key- Returns:
- The attribute value
-
removeAttribute
public final java.lang.Object removeAttribute(java.lang.CharSequence key)
Description copied from interface:BeanResolutionContext
Remove the attribute for the given key.- Specified by:
removeAttribute
in interfaceBeanResolutionContext
- Parameters:
key
- the key- Returns:
- The previous value
-
getCurrentQualifier
@Nullable public Qualifier<?> getCurrentQualifier()
- Specified by:
getCurrentQualifier
in interfaceBeanResolutionContext
- 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 interfaceBeanResolutionContext
- Parameters:
qualifier
- The qualifier
-
get
public <T> java.util.Optional<T> get(java.lang.CharSequence name, io.micronaut.core.convert.ArgumentConversionContext<T> conversionContext)
- Specified by:
get
in interfaceio.micronaut.core.value.ValueResolver<java.lang.CharSequence>
-
get
public <T> java.util.Optional<T> get(java.lang.CharSequence name, java.lang.Class<T> requiredType)
- Specified by:
get
in interfaceio.micronaut.core.value.ValueResolver<java.lang.CharSequence>
-
onNewSegment
protected void onNewSegment(BeanResolutionContext.Segment<?> segment)
-
-