Package io.micronaut.inject
Interface BeanDefinition<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
,BeanType<T>
,io.micronaut.core.naming.Named
- All Known Subinterfaces:
DelegatingBeanDefinition<T>
,DisposableBeanDefinition<T>
,InitializingBeanDefinition<T>
,ProxyBeanDefinition<T>
,RuntimeBeanDefinition<T>
,ValidatedBeanDefinition<T>
- All Known Implementing Classes:
AbstractBeanDefinition
,AbstractInitializableBeanDefinition
,AbstractParametrizedBeanDefinition
,AbstractProviderDefinition
,ApplicationEventPublisherFactory
,BeanProviderDefinition
,JakartaProviderBeanDefinition
,JavaxProviderBeanDefinition
public interface BeanDefinition<T> extends io.micronaut.core.annotation.AnnotationMetadataDelegate, io.micronaut.core.naming.Named, BeanType<T>, io.micronaut.core.type.ArgumentCoercible<T>
Defines a bean definition and its requirements. A bean definition must have a singled injectable constructor or a no-args constructor.- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
NAMED_ATTRIBUTE
Attribute used to store a dynamic bean name.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default io.micronaut.core.type.Argument<T>
asArgument()
default <R> java.util.Optional<ExecutableMethod<T,R>>
findMethod(java.lang.String name, java.lang.Class<?>... argumentTypes)
Finds a singleExecutableMethod
for the given name and argument types.default <R> java.util.stream.Stream<ExecutableMethod<T,R>>
findPossibleMethods(java.lang.String name)
Finds possible methods for the given method name.java.lang.Class<T>
getBeanType()
Returns the bean type.default ConstructorInjectionPoint<T>
getConstructor()
The single concrete constructor that is an injection point for creating the bean.default java.util.Optional<io.micronaut.core.type.Argument<?>>
getContainerElement()
IfBeanType.isContainerType()
returns true this will return the container element.default Qualifier<T>
getDeclaredQualifier()
Resolve the declared qualifier for this bean.default java.util.Optional<java.lang.Class<?>>
getDeclaringType()
default java.util.Collection<ExecutableMethod<T,?>>
getExecutableMethods()
default java.util.Collection<FieldInjectionPoint<T,?>>
getInjectedFields()
All the fields that require injection.default java.util.Collection<MethodInjectionPoint<T,?>>
getInjectedMethods()
All methods that require injection.default java.lang.String
getName()
default java.util.Collection<MethodInjectionPoint<T,?>>
getPostConstructMethods()
All the methods that should be called once the bean has been fully initialized and constructed.default java.util.Collection<MethodInjectionPoint<T,?>>
getPreDestroyMethods()
All the methods that should be called when the object is to be destroyed.default java.util.Collection<java.lang.Class<?>>
getRequiredComponents()
default <R> ExecutableMethod<T,R>
getRequiredMethod(java.lang.String name, java.lang.Class<?>... argumentTypes)
Finds a singleExecutableMethod
for the given name and argument types.default java.util.Optional<java.lang.Class<? extends java.lang.annotation.Annotation>>
getScope()
default java.util.Optional<java.lang.String>
getScopeName()
default java.util.List<io.micronaut.core.type.Argument<?>>
getTypeArguments()
If the bean itself declares any type arguments this method will return the classes that represent those types.default java.util.List<io.micronaut.core.type.Argument<?>>
getTypeArguments(java.lang.Class<?> type)
Return the type arguments for the given interface or super type for this bean.default java.util.List<io.micronaut.core.type.Argument<?>>
getTypeArguments(java.lang.String type)
Return the type arguments for the given interface or super type for this bean.default java.lang.Class<?>[]
getTypeParameters()
Returns the type parameters as a class array for the bean type.default java.lang.Class<?>[]
getTypeParameters(java.lang.Class<?> type)
Returns the type parameters as a class array for the given type.default T
inject(BeanContext context, T bean)
Inject the given bean with the context.default T
inject(BeanResolutionContext resolutionContext, BeanContext context, T bean)
Inject the given bean with the context.default boolean
isAbstract()
default boolean
isCandidateBean(io.micronaut.core.type.Argument<?> beanType)
Return whether this bean type is a candidate for dependency injection for the passed type.default boolean
isIterable()
default boolean
isProvided()
Deprecated.Provided beans are deprecateddefault boolean
isProxy()
Whether this bean definition represents a proxy.default boolean
isSingleton()
default Qualifier<T>
resolveDynamicQualifier()
-
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.core.annotation.AnnotationMetadataProvider
getAnnotationMetadata
-
Methods inherited from interface io.micronaut.inject.BeanContextConditional
isEnabled, isEnabled
-
Methods inherited from interface io.micronaut.inject.BeanType
getExposedTypes, isContainerType, isPrimary, requiresMethodProcessing
-
-
-
-
Method Detail
-
getScope
default java.util.Optional<java.lang.Class<? extends java.lang.annotation.Annotation>> getScope()
- Returns:
- The scope of the bean
-
getScopeName
default java.util.Optional<java.lang.String> getScopeName()
- Returns:
- The name of the scope
-
isSingleton
default boolean isSingleton()
- Returns:
- Whether the scope is singleton
-
getContainerElement
default java.util.Optional<io.micronaut.core.type.Argument<?>> getContainerElement()
IfBeanType.isContainerType()
returns true this will return the container element.- Returns:
- The container element.
-
isCandidateBean
default boolean isCandidateBean(@Nullable io.micronaut.core.type.Argument<?> beanType)
Description copied from interface:BeanType
Return whether this bean type is a candidate for dependency injection for the passed type.- Specified by:
isCandidateBean
in interfaceBeanType<T>
- Parameters:
beanType
- The bean type- Returns:
- True if it is
-
isProvided
@Deprecated default boolean isProvided()
Deprecated.Provided beans are deprecated- Returns:
- Is this definition provided by another bean
- See Also:
Provided
-
isIterable
default boolean isIterable()
- Returns:
- Whether the bean declared with
EachProperty
orEachBean
-
getBeanType
java.lang.Class<T> getBeanType()
Description copied from interface:BeanType
Returns the bean type.- Specified by:
getBeanType
in interfaceBeanType<T>
- Returns:
- The produced bean type
-
getDeclaringType
default java.util.Optional<java.lang.Class<?>> getDeclaringType()
- Returns:
- The type that declares this definition, null if not applicable.
-
getConstructor
default ConstructorInjectionPoint<T> getConstructor()
The single concrete constructor that is an injection point for creating the bean.- Returns:
- The constructor injection point
-
getRequiredComponents
default java.util.Collection<java.lang.Class<?>> getRequiredComponents()
- Returns:
- All required components for this entity definition
-
getInjectedMethods
default java.util.Collection<MethodInjectionPoint<T,?>> getInjectedMethods()
All methods that require injection. This is a subset of all the methods in the class.- Returns:
- The required properties
-
getInjectedFields
default java.util.Collection<FieldInjectionPoint<T,?>> getInjectedFields()
All the fields that require injection.- Returns:
- The required fields
-
getPostConstructMethods
default java.util.Collection<MethodInjectionPoint<T,?>> getPostConstructMethods()
All the methods that should be called once the bean has been fully initialized and constructed.- Returns:
- Methods to call post construct
-
getPreDestroyMethods
default java.util.Collection<MethodInjectionPoint<T,?>> getPreDestroyMethods()
All the methods that should be called when the object is to be destroyed.- Returns:
- Methods to call pre-destroy
-
getName
@NonNull default java.lang.String getName()
-
findMethod
default <R> java.util.Optional<ExecutableMethod<T,R>> findMethod(java.lang.String name, java.lang.Class<?>... argumentTypes)
Finds a singleExecutableMethod
for the given name and argument types.- Type Parameters:
R
- The return type- Parameters:
name
- The method nameargumentTypes
- The argument types- Returns:
- An optional
ExecutableMethod
-
findPossibleMethods
default <R> java.util.stream.Stream<ExecutableMethod<T,R>> findPossibleMethods(java.lang.String name)
Finds possible methods for the given method name.- Type Parameters:
R
- The return type- Parameters:
name
- The method name- Returns:
- The possible methods
-
inject
default T inject(BeanContext context, T bean)
Inject the given bean with the context.- Parameters:
context
- The contextbean
- The bean- Returns:
- The injected bean
-
inject
default T inject(BeanResolutionContext resolutionContext, BeanContext context, T bean)
Inject the given bean with the context.- Parameters:
resolutionContext
- the resolution contextcontext
- The contextbean
- The bean- Returns:
- The injected bean
-
getExecutableMethods
default java.util.Collection<ExecutableMethod<T,?>> getExecutableMethods()
- Returns:
- The
ExecutableMethod
instances for this definition
-
asArgument
@NonNull default io.micronaut.core.type.Argument<T> asArgument()
- Specified by:
asArgument
in interfaceio.micronaut.core.type.ArgumentCoercible<T>
-
isProxy
default boolean isProxy()
Whether this bean definition represents a proxy.- Returns:
- True if it represents a proxy
-
getTypeArguments
@NonNull default java.util.List<io.micronaut.core.type.Argument<?>> getTypeArguments()
If the bean itself declares any type arguments this method will return the classes that represent those types.- Returns:
- The type arguments
-
getTypeArguments
@NonNull default java.util.List<io.micronaut.core.type.Argument<?>> getTypeArguments(java.lang.Class<?> type)
Return the type arguments for the given interface or super type for this bean.- Parameters:
type
- The super class or interface type- Returns:
- The type arguments
-
getTypeParameters
@NonNull default java.lang.Class<?>[] getTypeParameters(@Nullable java.lang.Class<?> type)
Returns the type parameters as a class array for the given type.- Parameters:
type
- The type- Returns:
- The type parameters
-
getTypeParameters
@NonNull default java.lang.Class<?>[] getTypeParameters()
Returns the type parameters as a class array for the bean type.- Returns:
- The type parameters for the bean type as a class array.
-
getTypeArguments
@NonNull default java.util.List<io.micronaut.core.type.Argument<?>> getTypeArguments(java.lang.String type)
Return the type arguments for the given interface or super type for this bean.- Parameters:
type
- The super class or interface type- Returns:
- The type arguments
-
getRequiredMethod
default <R> ExecutableMethod<T,R> getRequiredMethod(java.lang.String name, java.lang.Class<?>... argumentTypes)
Finds a singleExecutableMethod
for the given name and argument types.- Type Parameters:
R
- The return type- Parameters:
name
- The method nameargumentTypes
- The argument types- Returns:
- An optional
ExecutableMethod
- Throws:
java.lang.IllegalStateException
- If the method cannot be found
-
isAbstract
default boolean isAbstract()
- Returns:
- Whether the bean definition is abstract
-
getDeclaredQualifier
@Nullable default Qualifier<T> getDeclaredQualifier()
Resolve the declared qualifier for this bean.- Returns:
- The qualifier or null if this isn't one
-
-