Interface RuntimeBeanDefinition.Builder<B>
- Type Parameters:
B- The bean type
- Enclosing interface:
RuntimeBeanDefinition<T>
RuntimeBeanDefinition instances.- Since:
- 3.6.0
- Author:
- graemerocher
-
Method Summary
Modifier and TypeMethodDescriptionannotationMetadata(@Nullable AnnotationMetadata annotationMetadata) The annotation metadata for the bean.build()Builds the runtime bean.disposer(@Nullable BiConsumer<BeanContext, B> disposer) The disposer to run when an instance created by this definition is destroyed.exposedTypes(Class<?>... types) Limit the exposed types of this bean.injectedDisposer(@Nullable BiConsumer<RuntimeBeanDefinition.DisposalContext, B> disposer) The disposer to run when an instance created by this definition is destroyed, receiving aRuntimeBeanDefinition.DisposalContextwith which it can resolve the beans it needs to do the disposal.default RuntimeBeanDefinition.Builder<B> injectionPoint(Argument<?> type) Declares an injection point of this bean.injectionPoint(Argument<?> type, @Nullable Qualifier<?> qualifier) Declares a qualified injection point of this bean.default RuntimeBeanDefinition.Builder<B> The qualifier to use.The qualifier to use.Adds this type as a bean replacement of the given type.scope(@Nullable Class<? extends Annotation> scope) The scope to use.singleton(boolean isSingleton) Is the bean singleton.typeArguments(Argument<?>... arguments) The type arguments for the type.typeArguments(Class<?> implementedType, Argument<?>... arguments) The type arguments for an implemented type of this type.
-
Method Details
-
qualifier
The qualifier to use.- Parameters:
qualifier- The qualifier- Returns:
- This builder
-
replaces
Adds this type as a bean replacement of the given type.- Parameters:
otherType- The other type- Returns:
- This bean builder
- Since:
- 4.0.0
-
named
The qualifier to use.- Parameters:
name- The named qualifier to use.- Returns:
- This builder
- Since:
- 3.7.0
-
scope
The scope to use.- Parameters:
scope- The scope- Returns:
- This builder
-
singleton
Is the bean singleton.- Parameters:
isSingleton- True if it is singleton- Returns:
- This builder
-
exposedTypes
Limit the exposed types of this bean.- Parameters:
types- The exposed types- Returns:
- This builder
-
typeArguments
The type arguments for the type.- Parameters:
arguments- The arguments- Returns:
- This builder
-
typeArguments
The type arguments for an implemented type of this type.- Parameters:
implementedType- The implemented typearguments- The arguments- Returns:
- This builder
-
annotationMetadata
RuntimeBeanDefinition.Builder<B> annotationMetadata(@Nullable AnnotationMetadata annotationMetadata) The annotation metadata for the bean.- Parameters:
annotationMetadata- The annotation metadata- Returns:
- This builder
-
injectionPoint
Declares an injection point of this bean.The declared injection points are resolved through the resolution context of the bean creation, in the order they were declared, and are handed to the bean factory of a definition built with
RuntimeBeanDefinition.builder(Argument, Function)as itsRuntimeBeanDefinition.CreationContext. Resolving them this way is what makes core's own dependency handling apply to a runtime built bean: a dependent object resolved for an injection point becomes a dependent of the created bean and is destroyed with it, a circular dependency is detected, and an unsatisfied injection point fails the creation with the usualDependencyInjectionException.An injection point declared with a
nullableargument resolves tonullinstead of failing when no bean is found.The declared injection points are also the arguments of
BeanDefinition.getConstructor()and the types ofBeanDefinition.getRequiredComponents(), so that the bean's dependencies can be described the way a compiled bean's are.- Parameters:
type- The type to inject- Returns:
- This builder
- Since:
- 5.2.0
-
injectionPoint
Declares a qualified injection point of this bean.- Parameters:
type- The type to injectqualifier- The qualifier, ornullfor none- Returns:
- This builder
- Since:
- 5.2.0
- See Also:
-
disposer
The disposer to run when an instance created by this definition is destroyed.The disposer is invoked once per instance, after the
BeanPreDestroyEventListenerinstances and before theBeanDestroyedEventListenerinstances, whenever the instance is destroyed by theBeanContext: when theBeanRegistrationof a non-singleton is closed, when a singleton is destroyed throughBeanContext.destroyBean(Object)or when the context itself is closed.A definition built with a disposer is a
DisposableBeanDefinition; a definition built without one is not, so existing definitions keep their current behaviour.A disposer that needs to resolve beans of its own takes a
RuntimeBeanDefinition.DisposalContextinstead, seeinjectedDisposer(BiConsumer). The two forms are alternatives: setting one clears the other.- Parameters:
disposer- The disposer, receiving the bean context and the instance being destroyed, ornullto clear a previously set disposer- Returns:
- This builder
- Since:
- 5.2.0
-
injectedDisposer
RuntimeBeanDefinition.Builder<B> injectedDisposer(@Nullable BiConsumer<RuntimeBeanDefinition.DisposalContext, B> disposer) The disposer to run when an instance created by this definition is destroyed, receiving aRuntimeBeanDefinition.DisposalContextwith which it can resolve the beans it needs to do the disposal.It is invoked at the same point in the destruction of the instance as
disposer(BiConsumer), and the two forms are alternatives: setting one clears the other.The lookups of the disposal context are resolved through a resolution context created for the disposal, which shares nothing with the creation of the bean being disposed of: what the disposer resolves is resolved fresh, and a dependent object among what it resolved is destroyed when the disposer returns rather than being kept for the lifetime of anything.
- Parameters:
disposer- The disposer, receiving the disposal context and the instance being destroyed, ornullto clear a previously set disposer- Returns:
- This builder
- Since:
- 5.2.0
-
build
-