Package io.micronaut.context
Interface BeanResolutionContext
- All Superinterfaces:
AutoCloseable,ValueResolver<CharSequence>
- All Known Implementing Classes:
AbstractBeanResolutionContext,DefaultBeanResolutionContext
Represents the resolution context for a current resolve of a given bean.
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceRepresents a path taken to resolve a bean definitions dependencies.static interfaceA segment in a path. -
Method Summary
Modifier and TypeMethodDescription<T> voidaddDependentBean(BeanRegistration<T> beanRegistration) Adds a dependent bean to the resolution context.<T> voidaddInFlightBean(BeanIdentifier beanIdentifier, BeanRegistration<T> beanRegistration) Adds a bean that is created as part of the resolution.default voidclose()copy()Copy current context to be used later.voidCall back to destroy anyInjectScopebeans.Find an optional bean of the given type and qualifier.default @NonNull List<BeanRegistration<?>>default @Nullable BeanRegistration<?>getAttribute(CharSequence key) Get the map representing current attributes.<T> TGet a bean of the given type and qualifier.<T> @NonNull Collection<BeanRegistration<T>>getBeanRegistrations(@NonNull Argument<T> beanType, @Nullable Qualifier<T> qualifier) Obtains the bean registrations for the given type and qualifier.<T> @NonNull Collection<T>getBeansOfType(@NonNull Argument<T> beanType, @Nullable Qualifier<T> qualifier) Get all beans of the given type and qualifier.<T> @Nullable BeanRegistration<T>getInFlightBean(BeanIdentifier beanIdentifier) Obtains an inflight bean for the given identifier.getPath()Obtains a map of beans of the given type and qualifier.default voidMarks first dependent as factory.default @Nullable List<BeanRegistration<?>>default voidpushDependentBeans(@Nullable List<BeanRegistration<?>> dependentBeans) The push the current dependent beans that must be destroyed by an upstream bean.Remove the attribute for the given key.voidremoveInFlightBean(BeanIdentifier beanIdentifier) Removes a bean that is in the process of being created.resolvePropertyValue(Argument<?> argument, String stringValue, String cliProperty, boolean isPlaceholder) Resolve a property value.setAttribute(CharSequence key, Object value) Store a value within the context.voidsetAttributes(@Nullable Map<CharSequence, Object> attributes) Set new attributes map (The map is supposed to be mutable).setConfigurationPath(@Nullable ConfigurationPath configurationPath) Sets the configuration path.voidsetCurrentQualifier(@Nullable Qualifier<?> qualifier) Sets the current qualifier.streamOfType(@NonNull Argument<T> beanType, @Nullable Qualifier<T> qualifier) Obtains a stream of beans of the given type and qualifier.voidvalueResolved(Argument<?> argument, Qualifier<?> qualifier, String property, @Nullable Object value) Callback when a value is resolved in some other context.Methods inherited from interface io.micronaut.core.value.ValueResolver
get, get, get, get
-
Method Details
-
close
default void close()- Specified by:
closein interfaceAutoCloseable
-
getBean
@NonNull <T> T getBean(@NonNull @NonNull Argument<T> beanType, @Nullable @Nullable Qualifier<T> qualifier) Get a bean of the given type and qualifier.- Type Parameters:
T- The bean type parameter- Parameters:
beanType- The bean typequalifier- The qualifier- Returns:
- The found bean
- Since:
- 3.5.0
-
getBeansOfType
@NonNull <T> @NonNull Collection<T> getBeansOfType(@NonNull @NonNull Argument<T> beanType, @Nullable @Nullable Qualifier<T> qualifier) Get all beans of the given type and qualifier.- Type Parameters:
T- The bean type parameter- Parameters:
beanType- The bean typequalifier- The qualifier- Returns:
- The found beans
- Since:
- 3.5.0
-
streamOfType
@NonNull <T> @NonNull Stream<T> streamOfType(@NonNull @NonNull Argument<T> beanType, @Nullable @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 typequalifier- The qualifier- Returns:
- A stream
- Since:
- 3.5.0
-
mapOfType
@NonNull default <V> @NonNull Map<String,V> mapOfType(@NonNull @NonNull Argument<V> beanType, @Nullable @Nullable Qualifier<V> qualifier) Obtains a map of beans of the given type and qualifier.- Type Parameters:
V- The bean type- Parameters:
beanType- The bean typequalifier- The qualifier- Returns:
- A map of beans, never
null. - Since:
- 4.0.0
-
findBean
@NonNull <T> @NonNull Optional<T> findBean(@NonNull @NonNull Argument<T> beanType, @Nullable @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 typequalifier- The qualifier- Returns:
- The found bean wrapped as an
Optional - Since:
- 3.5.0
-
getBeanRegistrations
@NonNull <T> @NonNull Collection<BeanRegistration<T>> getBeanRegistrations(@NonNull @NonNull Argument<T> beanType, @Nullable @Nullable Qualifier<T> qualifier) Obtains the bean registrations for the given type and qualifier.- Type Parameters:
T- The generic type- Parameters:
beanType- The bean typequalifier- The qualifier- Returns:
- A collection of
BeanRegistration - Since:
- 3.5.0
-
destroyInjectScopedBeans
void destroyInjectScopedBeans()Call back to destroy anyInjectScopebeans.- Since:
- 3.1.0
- See Also:
-
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
-
getPath
BeanResolutionContext.Path getPath()- Returns:
- The path that this resolution has taken so far
-
getConfigurationPath
- Returns:
- The configuration path.
- Since:
- 4.0.0
-
setAttribute
Store a value within the context.- Parameters:
key- The keyvalue- The value- Returns:
- The previous value or null
-
getAttribute
- Parameters:
key- The key- Returns:
- The attribute value
-
removeAttribute
Remove the attribute for the given key.- Parameters:
key- the key- Returns:
- The previous value
-
getAttributes
Get the map representing current attributes.- Returns:
- All attributes
- Since:
- 4.0.0
-
setAttributes
Set new attributes map (The map is supposed to be mutable).- Parameters:
attributes- The attributes- Since:
- 4.0.0
-
addInFlightBean
Adds a bean that is created as part of the resolution. This is used to store references to instances passed toBeanContext.inject(Object).- Type Parameters:
T- The instance type- Parameters:
beanIdentifier- The bean identifierbeanRegistration- The bean registration
-
removeInFlightBean
Removes a bean that is in the process of being created. This is used to store references to instances passed toBeanContext.inject(Object).- Parameters:
beanIdentifier- The bean identifier
-
getInFlightBean
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 aPostConstructmethod that also triggers bean resolution of the same bean.- Type Parameters:
T- The bean type- Parameters:
beanIdentifier- The bean identifier- Returns:
- The bean
-
getCurrentQualifier
- Returns:
- The current bean identifier
-
setCurrentQualifier
Sets the current qualifier.- Parameters:
qualifier- The qualifier
-
addDependentBean
Adds a dependent bean to the resolution context.- Type Parameters:
T- The generic type- Parameters:
beanRegistration- The bean registration
-
getAndResetDependentBeans
- Returns:
- The dependent beans that must be destroyed by an upstream bean
-
popDependentBeans
- Returns:
- The current dependent beans that must be destroyed by an upstream bean
- Since:
- 3.5.0
-
pushDependentBeans
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
- Returns:
- The dependent factory beans that was used to create the bean in context
- Since:
- 3.5.0
-
setConfigurationPath
@Nullable @Nullable ConfigurationPath setConfigurationPath(@Nullable @Nullable ConfigurationPath configurationPath) Sets the configuration path.- Parameters:
configurationPath- The configuration path.- Returns:
- The previous path
-
resolvePropertyValue
@Nullable @Nullable Object resolvePropertyValue(Argument<?> argument, String stringValue, String cliProperty, boolean isPlaceholder) Resolve a property value.- Parameters:
argument- The argumentstringValue- The string valuecliProperty- The CLI propertyisPlaceholder- Whether it is a place holder- Returns:
- The resolved value
-
valueResolved
void valueResolved(Argument<?> argument, Qualifier<?> qualifier, String property, @Nullable @Nullable Object value) Callback when a value is resolved in some other context.- Parameters:
argument- The argumentqualifier- The qualifierproperty- The propertyvalue- The value
-