Package io.micronaut.context
Interface RuntimeBeanDefinition<T>
-
- Type Parameters:
T
- The bean type
- All Superinterfaces:
io.micronaut.core.annotation.AnnotationMetadata
,io.micronaut.core.annotation.AnnotationMetadataDelegate
,io.micronaut.core.annotation.AnnotationMetadataProvider
,io.micronaut.core.annotation.AnnotationSource
,io.micronaut.core.type.ArgumentCoercible<T>
,BeanContextConditional
,BeanDefinition<T>
,BeanDefinitionReference<T>
,BeanFactory<T>
,BeanType<T>
,io.micronaut.core.naming.Named
public interface RuntimeBeanDefinition<T> extends BeanDefinitionReference<T>, BeanDefinition<T>, BeanFactory<T>, BeanContextConditional
Allow the construction for bean definitions programmatically that can be registered viaBeanDefinitionRegistry
at runtime.This differs from
BeanDefinitionRegistry.registerSingleton(Object)
in that beans registered this way can be created lazily or not at all and participate more completely in the life cycle of theBeanContext
(for examples event listeners likeBeanCreatedEventListener
will be fired).Note that it is generally not recommended to use this approach and build time bean computation is preferred. This type is designed to support a few limited use cases where runtime bean registration is required.
- Since:
- 3.6.0
- See Also:
BeanDefinitionRegistry.registerBeanDefinition(RuntimeBeanDefinition)
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
RuntimeBeanDefinition.Builder<B>
A builder for constructingRuntimeBeanDefinition
instances.
-
Field Summary
-
Fields inherited from interface io.micronaut.core.annotation.AnnotationMetadata
CLASS_NAME_SUFFIX, EMPTY_METADATA, VALUE_MEMBER
-
Fields inherited from interface io.micronaut.inject.BeanDefinition
NAMED_ATTRIBUTE
-
-
Method Summary
All Methods Static Methods Instance Methods Default Methods Modifier and Type Method Description static <B> RuntimeBeanDefinition.Builder<B>
builder(B bean)
A new builder for constructing and configuring runtime created beans.static <B> RuntimeBeanDefinition.Builder<B>
builder(io.micronaut.core.type.Argument<B> beanType, java.util.function.Supplier<B> beanSupplier)
A new builder for constructing and configuring runtime created beans.static <B> RuntimeBeanDefinition.Builder<B>
builder(java.lang.Class<B> beanType, java.util.function.Supplier<B> beanSupplier)
A new builder for constructing and configuring runtime created beans.default io.micronaut.core.annotation.AnnotationMetadata
getAnnotationMetadata()
default java.lang.String
getBeanDefinitionName()
default boolean
isContextScope()
default boolean
isEnabled(BeanContext context, BeanResolutionContext resolutionContext)
Return whether this component is enabled for the given context.default boolean
isPresent()
default boolean
isSingleton()
default BeanDefinition<T>
load()
Loads the bean definition.default BeanDefinition<T>
load(BeanContext context)
Loads the bean definition for the currentBeanContext
.static <B> RuntimeBeanDefinition<B>
of(B bean)
Creates a new effectively singleton bean definition that references the given bean.static <B> RuntimeBeanDefinition<B>
of(java.lang.Class<B> beanType, java.util.function.Supplier<B> beanSupplier)
Creates a new bean definition that will resolve the bean from the given supplier.-
Methods inherited from interface io.micronaut.core.annotation.AnnotationMetadata
getAnnotationValuesByName, getAnnotationValuesByStereotype, getDeclaredAnnotationValuesByName, getValues, hasDeclaredStereotype, isAnnotationPresent, isDeclaredAnnotationPresent
-
Methods inherited from interface io.micronaut.core.annotation.AnnotationMetadataDelegate
booleanValue, booleanValue, booleanValue, booleanValue, classValue, classValue, classValue, classValue, classValues, classValues, classValues, classValues, doubleValue, doubleValue, doubleValue, enumValue, enumValue, enumValue, enumValue, enumValues, enumValues, enumValues, enumValues, findAnnotation, findAnnotation, findDeclaredAnnotation, findDeclaredAnnotation, findRepeatableAnnotation, findRepeatableAnnotation, getAnnotation, getAnnotation, getAnnotationNameByStereotype, getAnnotationNameByStereotype, getAnnotationNames, getAnnotationNamesByStereotype, getAnnotationNamesByStereotype, getAnnotationType, getAnnotationType, getAnnotationTypeByStereotype, getAnnotationTypeByStereotype, getAnnotationTypesByStereotype, getAnnotationTypesByStereotype, getAnnotationTypesByStereotype, getAnnotationValuesByType, getDeclaredAnnotation, getDeclaredAnnotation, getDeclaredAnnotationNameByStereotype, getDeclaredAnnotationNames, getDeclaredAnnotationNamesByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationTypeByStereotype, getDeclaredAnnotationValuesByType, getDeclaredMetadata, getDeclaredStereotypeAnnotationNames, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValue, getDefaultValues, getStereotypeAnnotationNames, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValue, getValues, getValues, hasAnnotation, hasAnnotation, hasDeclaredAnnotation, hasDeclaredAnnotation, hasDeclaredStereotype, hasDeclaredStereotype, hasDeclaredStereotype, hasPropertyExpressions, hasSimpleAnnotation, hasSimpleDeclaredAnnotation, hasStereotype, hasStereotype, hasStereotype, hasStereotype, intValue, intValue, intValue, isAnnotationPresent, isDeclaredAnnotationPresent, isEmpty, isFalse, isFalse, isPresent, isPresent, isRepeatableAnnotation, isRepeatableAnnotation, isTrue, isTrue, longValue, longValue, stringValue, stringValue, stringValue, stringValue, stringValues, stringValues, stringValues, stringValues, synthesize, synthesize, synthesizeAll, synthesizeAnnotationsByType, synthesizeDeclared, synthesizeDeclared, synthesizeDeclared, synthesizeDeclaredAnnotationsByType
-
Methods inherited from interface io.micronaut.inject.BeanContextConditional
isEnabled
-
Methods inherited from interface io.micronaut.inject.BeanDefinition
asArgument, findMethod, findPossibleMethods, getBeanType, getConstructor, getContainerElement, getDeclaredQualifier, getDeclaringType, getExecutableMethods, getInjectedFields, getInjectedMethods, getName, getPostConstructMethods, getPreDestroyMethods, getRequiredComponents, getRequiredMethod, getScope, getScopeName, getTypeArguments, getTypeArguments, getTypeArguments, getTypeParameters, getTypeParameters, inject, inject, isAbstract, isCandidateBean, isIterable, isProvided, isProxy, resolveDynamicQualifier
-
Methods inherited from interface io.micronaut.inject.BeanDefinitionReference
isConfigurationProperties
-
Methods inherited from interface io.micronaut.inject.BeanFactory
build, build
-
Methods inherited from interface io.micronaut.inject.BeanType
getExposedTypes, getName, isContainerType, isPrimary, requiresMethodProcessing
-
-
-
-
Method Detail
-
getAnnotationMetadata
@NonNull default io.micronaut.core.annotation.AnnotationMetadata getAnnotationMetadata()
- Specified by:
getAnnotationMetadata
in interfaceio.micronaut.core.annotation.AnnotationMetadataProvider
-
isEnabled
default boolean isEnabled(@NonNull BeanContext context, BeanResolutionContext resolutionContext)
Description copied from interface:BeanContextConditional
Return whether this component is enabled for the given context.- Specified by:
isEnabled
in interfaceBeanContextConditional
- Parameters:
context
- The contextresolutionContext
- The bean resolution context- Returns:
- True if it is
-
isContextScope
default boolean isContextScope()
- Specified by:
isContextScope
in interfaceBeanDefinitionReference<T>
- Returns:
- Is this class context scope
-
load
default BeanDefinition<T> load()
Description copied from interface:BeanDefinitionReference
Loads the bean definition.- Specified by:
load
in interfaceBeanDefinitionReference<T>
- Returns:
- The loaded component definition or null if it shouldn't be loaded
-
getBeanDefinitionName
default java.lang.String getBeanDefinitionName()
- Specified by:
getBeanDefinitionName
in interfaceBeanDefinitionReference<T>
- Returns:
- The class name of the backing
BeanDefinition
-
load
default BeanDefinition<T> load(BeanContext context)
Description copied from interface:BeanDefinitionReference
Loads the bean definition for the currentBeanContext
.- Specified by:
load
in interfaceBeanDefinitionReference<T>
- Parameters:
context
- The bean context- Returns:
- The loaded bean definition or null if it shouldn't be loaded
-
isPresent
default boolean isPresent()
- Specified by:
isPresent
in interfaceBeanDefinitionReference<T>
- Returns:
- Is the underlying bean type present on the classpath
-
isSingleton
default boolean isSingleton()
- Specified by:
isSingleton
in interfaceBeanDefinition<T>
- Specified by:
isSingleton
in interfaceBeanDefinitionReference<T>
- Returns:
- Is this bean a singleton.
-
of
@NonNull static <B> RuntimeBeanDefinition<B> of(@NonNull B bean)
Creates a new effectively singleton bean definition that references the given bean.- Type Parameters:
B
- The bean type- Parameters:
bean
- The bean- Returns:
- The
BeanDefinitionReference
- Since:
- 3.6.0
-
of
@NonNull static <B> RuntimeBeanDefinition<B> of(@NonNull java.lang.Class<B> beanType, @NonNull java.util.function.Supplier<B> beanSupplier)
Creates a new bean definition that will resolve the bean from the given supplier.The bean is by default not singleton and the supplier will be invoked for each injection point.
- Type Parameters:
B
- The bean type- Parameters:
beanType
- The bean typebeanSupplier
- The bean supplier- Returns:
- The
BeanDefinitionReference
- Since:
- 3.6.0
-
builder
@NonNull static <B> RuntimeBeanDefinition.Builder<B> builder(@NonNull B bean)
A new builder for constructing and configuring runtime created beans.- Type Parameters:
B
- The bean type- Parameters:
bean
- The bean to use- Returns:
- The builder
-
builder
@NonNull static <B> RuntimeBeanDefinition.Builder<B> builder(@NonNull java.lang.Class<B> beanType, @NonNull java.util.function.Supplier<B> beanSupplier)
A new builder for constructing and configuring runtime created beans.- Type Parameters:
B
- The bean type- Parameters:
beanType
- The bean typebeanSupplier
- The bean supplier- Returns:
- The builder
-
builder
@NonNull static <B> RuntimeBeanDefinition.Builder<B> builder(@NonNull io.micronaut.core.type.Argument<B> beanType, @NonNull java.util.function.Supplier<B> beanSupplier)
A new builder for constructing and configuring runtime created beans.- Type Parameters:
B
- The bean type- Parameters:
beanType
- The bean typebeanSupplier
- The bean supplier- Returns:
- The builder
-
-