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 theBeanResolutionContextinterface.- Since:
- 1.2.3
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractBeanResolutionContext.AnnotationSegmentA segment that represents annotation.static classAbstractBeanResolutionContext.ConstructorArgumentSegmentA segment that represents a method argument.static classAbstractBeanResolutionContext.ConstructorSegmentA segment that represents a constructor.static classAbstractBeanResolutionContext.FieldSegmentA segment that represents a field.static classAbstractBeanResolutionContext.MethodArgumentSegmentA segment that represents a method argument.static classAbstractBeanResolutionContext.MethodSegmentA 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 DefaultBeanContextcontextprotected BeanResolutionContext.Pathpathprotected BeanDefinition<?>rootDefinition
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractBeanResolutionContext(DefaultBeanContext context, BeanDefinition<?> rootDefinition)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> voidaddDependentBean(BeanRegistration<T> beanRegistration)Adds a dependent bean to the resolution context.voidcopyStateFrom(AbstractBeanResolutionContext context)Copy the state from a previous resolution context.voiddestroyInjectScopedBeans()Call back to destroy anyInjectScopebeans.<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.ObjectgetAttribute(java.lang.CharSequence key)<T> TgetBean(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.BeanContextgetContext()Qualifier<?>getCurrentQualifier()BeanResolutionContext.PathgetPath()BeanDefinitiongetRootDefinition()<T> Tinject(BeanDefinition<?> beanDefinition, T instance)Injects a bean.voidmarkDependentAsFactory()Marks first dependent as factory.protected voidonNewSegment(BeanResolutionContext.Segment<?> segment)java.util.List<BeanRegistration<?>>popDependentBeans()voidpushDependentBeans(java.util.List<BeanRegistration<?>> dependentBeans)The push the current dependent beans that must be destroyed by an upstream bean.java.lang.ObjectremoveAttribute(java.lang.CharSequence key)Remove the attribute for the given key.java.lang.ObjectsetAttribute(java.lang.CharSequence key, java.lang.Object value)Store a value within the context.voidsetCurrentQualifier(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:BeanResolutionContextGet a bean of the given type and qualifier.- Specified by:
getBeanin 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:BeanResolutionContextGet all beans of the given type and qualifier.- Specified by:
getBeansOfTypein 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:BeanResolutionContextObtains a stream of beans of the given type and qualifier.- Specified by:
streamOfTypein 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:BeanResolutionContextFind an optional bean of the given type and qualifier.- Specified by:
findBeanin 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:BeanResolutionContextInjects a bean.- Specified by:
injectin 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:BeanResolutionContextObtains the bean registrations for the given type and qualifier.- Specified by:
getBeanRegistrationsin 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:BeanResolutionContextAdds a dependent bean to the resolution context.- Specified by:
addDependentBeanin interfaceBeanResolutionContext- Type Parameters:
T- The generic type- Parameters:
beanRegistration- The bean registration
-
destroyInjectScopedBeans
public void destroyInjectScopedBeans()
Description copied from interface:BeanResolutionContextCall back to destroy anyInjectScopebeans.- Specified by:
destroyInjectScopedBeansin interfaceBeanResolutionContext- See Also:
InjectScope
-
getAndResetDependentBeans
@NonNull public java.util.List<BeanRegistration<?>> getAndResetDependentBeans()
- Specified by:
getAndResetDependentBeansin interfaceBeanResolutionContext- Returns:
- The dependent beans that must be destroyed by an upstream bean
-
markDependentAsFactory
public void markDependentAsFactory()
Description copied from interface:BeanResolutionContextMarks first dependent as factory. Dependent can be missing which means it's a singleton or scoped bean.- Specified by:
markDependentAsFactoryin interfaceBeanResolutionContext
-
getAndResetDependentFactoryBean
public BeanRegistration<?> getAndResetDependentFactoryBean()
- Specified by:
getAndResetDependentFactoryBeanin interfaceBeanResolutionContext- Returns:
- The dependent factory beans that was used to create the bean in context
-
popDependentBeans
public java.util.List<BeanRegistration<?>> popDependentBeans()
- Specified by:
popDependentBeansin 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:BeanResolutionContextThe push the current dependent beans that must be destroyed by an upstream bean.- Specified by:
pushDependentBeansin interfaceBeanResolutionContext- Parameters:
dependentBeans- Dependent beans collection that can be used to add more dependents
-
getContext
public final BeanContext getContext()
- Specified by:
getContextin interfaceBeanResolutionContext- Returns:
- The context
-
getRootDefinition
public final BeanDefinition getRootDefinition()
- Specified by:
getRootDefinitionin interfaceBeanResolutionContext- Returns:
- The class requested at the root of this resolution context
-
getPath
public final BeanResolutionContext.Path getPath()
- Specified by:
getPathin 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:BeanResolutionContextStore a value within the context.- Specified by:
setAttributein 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:
getAttributein interfaceBeanResolutionContext- Parameters:
key- The key- Returns:
- The attribute value
-
removeAttribute
public final java.lang.Object removeAttribute(java.lang.CharSequence key)
Description copied from interface:BeanResolutionContextRemove the attribute for the given key.- Specified by:
removeAttributein interfaceBeanResolutionContext- Parameters:
key- the key- Returns:
- The previous value
-
getCurrentQualifier
@Nullable public Qualifier<?> getCurrentQualifier()
- Specified by:
getCurrentQualifierin interfaceBeanResolutionContext- Returns:
- The current bean identifier
-
setCurrentQualifier
public void setCurrentQualifier(@Nullable Qualifier<?> qualifier)Description copied from interface:BeanResolutionContextSets the current qualifier.- Specified by:
setCurrentQualifierin 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:
getin 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:
getin interfaceio.micronaut.core.value.ValueResolver<java.lang.CharSequence>
-
onNewSegment
protected void onNewSegment(BeanResolutionContext.Segment<?> segment)
-
-