Interface BeanDefinitionRegistry
-
- All Known Subinterfaces:
ApplicationContext
,BeanContext
,InitializableBeanContext
- All Known Implementing Classes:
DefaultApplicationContext
,DefaultBeanContext
public interface BeanDefinitionRegistry
Core bean definition registry interface containing methods to find
BeanDefinition
instances.- Since:
- 1.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <T> boolean
containsBean(io.micronaut.core.type.Argument<T> beanType)
Return whether the bean of the given type is contained within this context.default <T> boolean
containsBean(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Return whether the bean of the given type is contained within this context.default boolean
containsBean(java.lang.Class<?> beanType)
Return whether the bean of the given type is contained within this context.<T> boolean
containsBean(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Return whether the bean of the given type is contained within this context.java.util.Optional<BeanConfiguration>
findBeanConfiguration(java.lang.String configurationName)
Obtain a bean configuration by name.default <T> java.util.Optional<BeanDefinition<T>>
findBeanDefinition(io.micronaut.core.type.Argument<T> beanType)
Obtain aBeanDefinition
for the given type.default <T> java.util.Optional<BeanDefinition<T>>
findBeanDefinition(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Obtain aBeanDefinition
for the given type.default <T> java.util.Optional<BeanDefinition<T>>
findBeanDefinition(java.lang.Class<T> beanType)
Obtain aBeanDefinition
for the given type.<T> java.util.Optional<BeanDefinition<T>>
findBeanDefinition(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Obtain aBeanDefinition
for the given type.<T> java.util.Optional<BeanRegistration<T>>
findBeanRegistration(T bean)
Obtain aBeanDefinition
for the given bean.<T> java.util.Optional<BeanDefinition<T>>
findProxyBeanDefinition(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Obtain the proxyBeanDefinition
for the bean of type and qualifier.<T> java.util.Optional<BeanDefinition<T>>
findProxyBeanDefinition(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Obtain the proxyBeanDefinition
for the bean of type and qualifier.default <T> java.util.Optional<BeanDefinition<T>>
findProxyTargetBeanDefinition(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Obtain the originalBeanDefinition
for aProxyBeanDefinition
.default <T> java.util.Optional<BeanDefinition<T>>
findProxyTargetBeanDefinition(BeanDefinition<T> proxyBeanDefinition)
Obtain the originalBeanDefinition
for aProxyBeanDefinition
.<T> java.util.Optional<BeanDefinition<T>>
findProxyTargetBeanDefinition(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Obtain the originalBeanDefinition
for aProxyBeanDefinition
.java.util.Collection<BeanRegistration<?>>
getActiveBeanRegistrations(Qualifier<?> qualifier)
Find activeSingleton
beans for the given qualifier.<T> java.util.Collection<BeanRegistration<T>>
getActiveBeanRegistrations(java.lang.Class<T> beanType)
Find activeSingleton
beans for the given bean type.java.util.Collection<BeanDefinition<?>>
getAllBeanDefinitions()
Get all of the registeredBeanDefinition
.default <T> BeanDefinition<T>
getBeanDefinition(io.micronaut.core.type.Argument<T> beanType)
Obtain aBeanDefinition
for the given type.default <T> BeanDefinition<T>
getBeanDefinition(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Obtain aBeanDefinition
for the given type.default <T> BeanDefinition<T>
getBeanDefinition(java.lang.Class<T> beanType)
Obtain aBeanDefinition
for the given type.default <T> BeanDefinition<T>
getBeanDefinition(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Obtain aBeanDefinition
for the given type.java.util.Collection<BeanDefinitionReference<?>>
getBeanDefinitionReferences()
Get all of the enabledBeanDefinitionReference
.java.util.Collection<BeanDefinition<?>>
getBeanDefinitions(Qualifier<java.lang.Object> qualifier)
Get all of theBeanDefinition
for the given qualifier.default <T> java.util.Collection<BeanDefinition<T>>
getBeanDefinitions(io.micronaut.core.type.Argument<T> beanType)
Obtain aBeanDefinition
for the given type.default <T> java.util.Collection<BeanDefinition<T>>
getBeanDefinitions(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Obtain aBeanDefinition
for the given type.<T> java.util.Collection<BeanDefinition<T>>
getBeanDefinitions(java.lang.Class<T> beanType)
Obtain aBeanDefinition
for the given type.<T> java.util.Collection<BeanDefinition<T>>
getBeanDefinitions(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Obtain aBeanDefinition
for the given type.default <T> BeanRegistration<T>
getBeanRegistration(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Find a bean registration for the given bean type and optional qualifier.<T> BeanRegistration<T>
getBeanRegistration(BeanDefinition<T> beanDefinition)
Find a bean registration for the given bean definition.<T> BeanRegistration<T>
getBeanRegistration(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Find a bean registration for the given bean type and optional qualifier.default <T> java.util.Collection<BeanRegistration<T>>
getBeanRegistrations(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Find and if necessary initializeSingleton
beans for the given bean type, returning all the active registrations.<T> java.util.Collection<BeanRegistration<T>>
getBeanRegistrations(java.lang.Class<T> beanType)
Find and if necessary initializeSingleton
beans for the given bean type, returning all the active registrations.<T> java.util.Collection<BeanRegistration<T>>
getBeanRegistrations(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Find and if necessary initializeSingleton
beans for the given bean type, returning all the active registrations.default <T> BeanDefinition<T>
getProxyTargetBeanDefinition(io.micronaut.core.type.Argument<T> beanType, Qualifier<T> qualifier)
Obtain the originalBeanDefinition
for aProxyBeanDefinition
.default <T> BeanDefinition<T>
getProxyTargetBeanDefinition(java.lang.Class<T> beanType, Qualifier<T> qualifier)
Obtain the originalBeanDefinition
for aProxyBeanDefinition
.default <B> BeanDefinitionRegistry
registerBeanDefinition(RuntimeBeanDefinition<B> definition)
Registers a new reference at runtime.default <T> BeanDefinitionRegistry
registerSingleton(java.lang.Class<T> type, T singleton)
Registers a new singleton bean at runtime.default <T> BeanDefinitionRegistry
registerSingleton(java.lang.Class<T> type, T singleton, Qualifier<T> qualifier)
Registers a new singleton bean at runtime.<T> BeanDefinitionRegistry
registerSingleton(java.lang.Class<T> type, T singleton, Qualifier<T> qualifier, boolean inject)
Registers a new singleton bean at runtime.default BeanDefinitionRegistry
registerSingleton(java.lang.Object singleton)
Registers a new singleton bean at runtime.default BeanDefinitionRegistry
registerSingleton(java.lang.Object singleton, boolean inject)
Registers a new singleton bean at runtime.
-
-
-
Method Detail
-
containsBean
<T> boolean containsBean(@NonNull java.lang.Class<T> beanType, @Nullable Qualifier<T> qualifier)
Return whether the bean of the given type is contained within this context.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The bean typequalifier
- The qualifier for the bean- Returns:
- True if it is
-
containsBean
default <T> boolean containsBean(@NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Return whether the bean of the given type is contained within this context.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The bean typequalifier
- The qualifier for the bean- Returns:
- True if it is
- Since:
- 3.0.0
-
containsBean
default <T> boolean containsBean(@NonNull io.micronaut.core.type.Argument<T> beanType)
Return whether the bean of the given type is contained within this context.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The bean type- Returns:
- True if it is
- Since:
- 3.0.0
-
registerBeanDefinition
@NonNull default <B> BeanDefinitionRegistry registerBeanDefinition(@NonNull RuntimeBeanDefinition<B> definition)
Registers a new reference at runtime. Not that registering beans can impact the object graph therefore should this should be done as soon as possible prior to the creation of other beans preferably with a high priorityContext
scope bean.- Type Parameters:
B
- The bean type- Parameters:
definition
- The reference.- Returns:
- The registry
- Since:
- 3.6.0
-
registerSingleton
@NonNull <T> BeanDefinitionRegistry registerSingleton(@NonNull java.lang.Class<T> type, @NonNull T singleton, @Nullable Qualifier<T> qualifier, boolean inject)
Registers a new singleton bean at runtime. This method expects that the bean definition data will have been compiled ahead of time.
If bean definition data is found the method will perform dependency injection on the instance followed by invoking any
PostConstruct
hooks.If no bean definition data is found the bean is registered as is.
- Type Parameters:
T
- The concrete type- Parameters:
type
- The bean typesingleton
- The singleton beanqualifier
- The bean qualifierinject
- Whether the singleton should be injected (defaults to true)- Returns:
- This bean context
-
findBeanConfiguration
@NonNull java.util.Optional<BeanConfiguration> findBeanConfiguration(@NonNull java.lang.String configurationName)
Obtain a bean configuration by name.- Parameters:
configurationName
- The configuration name- Returns:
- An optional with the configuration either present or not
-
findBeanDefinition
@NonNull <T> java.util.Optional<BeanDefinition<T>> findBeanDefinition(@NonNull java.lang.Class<T> beanType, @Nullable Qualifier<T> qualifier)
Obtain aBeanDefinition
for the given type.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The typequalifier
- The qualifier- Returns:
- An
Optional
of the bean definition - Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given type
-
findBeanDefinition
@NonNull default <T> java.util.Optional<BeanDefinition<T>> findBeanDefinition(@NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Obtain aBeanDefinition
for the given type.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The potentially parameterized typequalifier
- The qualifier- Returns:
- An
Optional
of the bean definition - Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given type- Since:
- 3.0.0
-
findBeanDefinition
@NonNull default <T> java.util.Optional<BeanDefinition<T>> findBeanDefinition(@NonNull io.micronaut.core.type.Argument<T> beanType)
Obtain aBeanDefinition
for the given type.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The potentially parameterized type- Returns:
- An
Optional
of the bean definition - Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given type- Since:
- 3.0.0
-
findBeanRegistration
@NonNull <T> java.util.Optional<BeanRegistration<T>> findBeanRegistration(@NonNull T bean)
Obtain aBeanDefinition
for the given bean.- Type Parameters:
T
- The concrete type- Parameters:
bean
- The bean- Returns:
- An
Optional
of the bean definition - Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given type
-
getBeanDefinitions
@NonNull <T> java.util.Collection<BeanDefinition<T>> getBeanDefinitions(@NonNull java.lang.Class<T> beanType)
Obtain aBeanDefinition
for the given type.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The type- Returns:
- An
Optional
of the bean definition - Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given type
-
getBeanDefinitions
@NonNull default <T> java.util.Collection<BeanDefinition<T>> getBeanDefinitions(@NonNull io.micronaut.core.type.Argument<T> beanType)
Obtain aBeanDefinition
for the given type.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The type- Returns:
- An
Optional
of the bean definition - Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given type- Since:
- 3.0.0
-
getBeanDefinitions
@NonNull <T> java.util.Collection<BeanDefinition<T>> getBeanDefinitions(@NonNull java.lang.Class<T> beanType, @Nullable Qualifier<T> qualifier)
Obtain aBeanDefinition
for the given type.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The typequalifier
- The qualifier- Returns:
- An
Optional
of the bean definition - Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given type
-
getBeanDefinitions
@NonNull default <T> java.util.Collection<BeanDefinition<T>> getBeanDefinitions(@NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Obtain aBeanDefinition
for the given type.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The typequalifier
- The qualifier- Returns:
- An
Optional
of the bean definition - Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given type- Since:
- 3.0.0
-
getBeanDefinitions
@NonNull java.util.Collection<BeanDefinition<?>> getBeanDefinitions(@NonNull Qualifier<java.lang.Object> qualifier)
Get all of theBeanDefinition
for the given qualifier.- Parameters:
qualifier
- The qualifier- Returns:
- The bean definitions
-
getAllBeanDefinitions
@NonNull java.util.Collection<BeanDefinition<?>> getAllBeanDefinitions()
Get all of the registeredBeanDefinition
.- Returns:
- The bean definitions
-
getBeanDefinitionReferences
@NonNull java.util.Collection<BeanDefinitionReference<?>> getBeanDefinitionReferences()
Get all of the enabledBeanDefinitionReference
.- Returns:
- The bean definitions
-
getActiveBeanRegistrations
@NonNull java.util.Collection<BeanRegistration<?>> getActiveBeanRegistrations(@NonNull Qualifier<?> qualifier)
Find activeSingleton
beans for the given qualifier. Note that this method can return multiple registrations for a given singleton bean instance since each bean may have multiple qualifiers.- Parameters:
qualifier
- The qualifier- Returns:
- The beans
-
getActiveBeanRegistrations
@NonNull <T> java.util.Collection<BeanRegistration<T>> getActiveBeanRegistrations(@NonNull java.lang.Class<T> beanType)
Find activeSingleton
beans for the given bean type. Note that this method can return multiple registrations for a given singleton bean instance since each bean may have multiple qualifiers.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The bean type- Returns:
- The beans
-
getBeanRegistrations
@NonNull <T> java.util.Collection<BeanRegistration<T>> getBeanRegistrations(@NonNull java.lang.Class<T> beanType)
Find and if necessary initializeSingleton
beans for the given bean type, returning all the active registrations. Note that this method can return multiple registrations for a given singleton bean instance since each bean may have multiple qualifiers.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The bean type- Returns:
- The beans
-
getBeanRegistrations
@NonNull <T> java.util.Collection<BeanRegistration<T>> getBeanRegistrations(@NonNull java.lang.Class<T> beanType, @Nullable Qualifier<T> qualifier)
Find and if necessary initializeSingleton
beans for the given bean type, returning all the active registrations. Note that this method can return multiple registrations for a given singleton bean instance since each bean may have multiple qualifiers.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- The beans
- Since:
- 2.4.0
-
getBeanRegistrations
@NonNull default <T> java.util.Collection<BeanRegistration<T>> getBeanRegistrations(@NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Find and if necessary initializeSingleton
beans for the given bean type, returning all the active registrations. Note that this method can return multiple registrations for a given singleton bean instance since each bean may have multiple qualifiers.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- The beans
- Since:
- 3.0.0
-
getBeanRegistration
@NonNull <T> BeanRegistration<T> getBeanRegistration(@NonNull java.lang.Class<T> beanType, @Nullable Qualifier<T> qualifier)
Find a bean registration for the given bean type and optional qualifier.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- The bean registration
- Throws:
NoSuchBeanException
- if the bean doesn't exist- Since:
- 2.4.0
-
getBeanRegistration
@NonNull default <T> BeanRegistration<T> getBeanRegistration(@NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Find a bean registration for the given bean type and optional qualifier.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The potentially parameterized bean typequalifier
- The qualifier- Returns:
- The bean registration
- Throws:
NoSuchBeanException
- if the bean doesn't exist- Since:
- 3.0.0
-
getBeanRegistration
@NonNull <T> BeanRegistration<T> getBeanRegistration(@NonNull BeanDefinition<T> beanDefinition)
Find a bean registration for the given bean definition.- Type Parameters:
T
- The concrete type- Parameters:
beanDefinition
- The bean definition- Returns:
- The bean registration
- Throws:
NoSuchBeanException
- if the bean doesn't exist- Since:
- 3.5.0
-
findProxyTargetBeanDefinition
@NonNull <T> java.util.Optional<BeanDefinition<T>> findProxyTargetBeanDefinition(@NonNull java.lang.Class<T> beanType, @Nullable Qualifier<T> qualifier)
Obtain the originalBeanDefinition
for aProxyBeanDefinition
.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The typequalifier
- The qualifier- Returns:
- An
Optional
of the bean definition - Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given type
-
findProxyTargetBeanDefinition
@NonNull default <T> java.util.Optional<BeanDefinition<T>> findProxyTargetBeanDefinition(@NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Obtain the originalBeanDefinition
for aProxyBeanDefinition
.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The typequalifier
- The qualifier- Returns:
- An
Optional
of the bean definition - Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given type
-
findProxyTargetBeanDefinition
@NonNull default <T> java.util.Optional<BeanDefinition<T>> findProxyTargetBeanDefinition(@NonNull BeanDefinition<T> proxyBeanDefinition)
Obtain the originalBeanDefinition
for aProxyBeanDefinition
.- Type Parameters:
T
- The concrete type- Parameters:
proxyBeanDefinition
- The proxy bean definition- Returns:
- An
Optional
of the bean definition - Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given type- Since:
- 3.5.0
-
findProxyBeanDefinition
@NonNull <T> java.util.Optional<BeanDefinition<T>> findProxyBeanDefinition(@NonNull java.lang.Class<T> beanType, @Nullable Qualifier<T> qualifier)
Obtain the proxyBeanDefinition
for the bean of type and qualifier.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The typequalifier
- The qualifier- Returns:
- An
Optional
of the bean definition - Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given type
-
findProxyBeanDefinition
@NonNull <T> java.util.Optional<BeanDefinition<T>> findProxyBeanDefinition(@NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Obtain the proxyBeanDefinition
for the bean of type and qualifier.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The typequalifier
- The qualifier- Returns:
- An
Optional
of the bean definition - Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given type
-
registerSingleton
@NonNull default <T> BeanDefinitionRegistry registerSingleton(@NonNull java.lang.Class<T> type, @NonNull T singleton, @Nullable Qualifier<T> qualifier)
Registers a new singleton bean at runtime. This method expects that the bean definition data will have been compiled ahead of time.
If bean definition data is found the method will perform dependency injection on the instance followed by invoking any
PostConstruct
hooks.If no bean definition data is found the bean is registered as is.
- Type Parameters:
T
- The concrete type- Parameters:
type
- The bean typesingleton
- The singleton beanqualifier
- The bean qualifier- Returns:
- This bean context
-
registerSingleton
default <T> BeanDefinitionRegistry registerSingleton(@NonNull java.lang.Class<T> type, @NonNull T singleton)
Registers a new singleton bean at runtime. This method expects that the bean definition data will have been compiled ahead of time.
If bean definition data is found the method will perform dependency injection on the instance followed by invoking any
PostConstruct
hooks.If no bean definition data is found the bean is registered as is.
- Type Parameters:
T
- The concrete type- Parameters:
type
- the bean typesingleton
- The singleton bean- Returns:
- This bean context
-
getBeanDefinition
@NonNull default <T> BeanDefinition<T> getBeanDefinition(@NonNull java.lang.Class<T> beanType, @Nullable Qualifier<T> qualifier)
Obtain aBeanDefinition
for the given type.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The typequalifier
- The qualifier- Returns:
- The
BeanDefinition
- Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given typeNoSuchBeanException
- If the bean cannot be found
-
getBeanDefinition
@NonNull default <T> BeanDefinition<T> getBeanDefinition(@NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Obtain aBeanDefinition
for the given type.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The potentially parameterized type typequalifier
- The qualifier- Returns:
- The
BeanDefinition
- Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given typeNoSuchBeanException
- If the bean cannot be found- Since:
- 3.0.
-
getProxyTargetBeanDefinition
@NonNull default <T> BeanDefinition<T> getProxyTargetBeanDefinition(@NonNull java.lang.Class<T> beanType, @Nullable Qualifier<T> qualifier)
Obtain the originalBeanDefinition
for aProxyBeanDefinition
.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The typequalifier
- The qualifier- Returns:
- The
BeanDefinition
- Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given typeNoSuchBeanException
- If the bean cannot be found
-
getProxyTargetBeanDefinition
@NonNull default <T> BeanDefinition<T> getProxyTargetBeanDefinition(@NonNull io.micronaut.core.type.Argument<T> beanType, @Nullable Qualifier<T> qualifier)
Obtain the originalBeanDefinition
for aProxyBeanDefinition
.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The typequalifier
- The qualifier- Returns:
- The
BeanDefinition
- Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given typeNoSuchBeanException
- If the bean cannot be found- Since:
- 3.0.0
-
getBeanDefinition
@NonNull default <T> BeanDefinition<T> getBeanDefinition(@NonNull java.lang.Class<T> beanType)
Obtain aBeanDefinition
for the given type.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The type- Returns:
- The
BeanDefinition
- Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given typeNoSuchBeanException
- If the bean cannot be found
-
getBeanDefinition
@NonNull default <T> BeanDefinition<T> getBeanDefinition(@NonNull io.micronaut.core.type.Argument<T> beanType)
Obtain aBeanDefinition
for the given type.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The type- Returns:
- The
BeanDefinition
- Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given typeNoSuchBeanException
- If the bean cannot be found- Since:
- 3.0.0
-
findBeanDefinition
@NonNull default <T> java.util.Optional<BeanDefinition<T>> findBeanDefinition(@NonNull java.lang.Class<T> beanType)
Obtain aBeanDefinition
for the given type.- Type Parameters:
T
- The concrete type- Parameters:
beanType
- The type- Returns:
- An
Optional
of the bean definition - Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given type
-
registerSingleton
@NonNull default BeanDefinitionRegistry registerSingleton(@NonNull java.lang.Object singleton)
Registers a new singleton bean at runtime. This method expects that the bean definition data will have been compiled ahead of time.
If bean definition data is found the method will perform dependency injection on the instance followed by invoking any
PostConstruct
hooks.If no bean definition data is found the bean is registered as is.
- Parameters:
singleton
- The singleton bean- Returns:
- This bean context
-
registerSingleton
@NonNull default BeanDefinitionRegistry registerSingleton(@NonNull java.lang.Object singleton, boolean inject)
Registers a new singleton bean at runtime. This method expects that the bean definition data will have been compiled ahead of time.
If bean definition data is found the method will perform dependency injection on the instance followed by invoking any
PostConstruct
hooks.If no bean definition data is found the bean is registered as is.
- Parameters:
singleton
- The singleton beaninject
- Whether the singleton should be injected (defaults to true)- Returns:
- This bean context
-
containsBean
default boolean containsBean(@NonNull java.lang.Class<?> beanType)
Return whether the bean of the given type is contained within this context.- Parameters:
beanType
- The bean type- Returns:
- True if it is
-
-