T
- The type of aggregate generated by this aggregate factory.public class SpringPrototypeAggregateFactory<T> extends Object implements AggregateFactory<T>, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.BeanNameAware
AggregateFactory
implementation that uses Spring prototype beans to create new uninitialized instances of
Aggregates.Constructor and Description |
---|
SpringPrototypeAggregateFactory(Class<T> aggregateType,
String prototypeBeanName,
Map<Class<? extends T>,String> subtypes)
Initializes the factory to create bean instances from the given
prototypeBeanName or its
subtypes . |
SpringPrototypeAggregateFactory(String prototypeBeanName)
Deprecated.
In favor of
SpringPrototypeAggregateFactory(Class, String, Map) to ensure all required
fields are present for both polymorphic and non-polymorphic aggregates. |
SpringPrototypeAggregateFactory(String prototypeBeanName,
Map<Class<? extends T>,String> subtypes)
Deprecated.
In favor of
SpringPrototypeAggregateFactory(Class, String, Map) to ensure all required
fields are present for both polymorphic and non-polymorphic aggregates. |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
T |
createAggregateRoot(String aggregateIdentifier,
DomainEventMessage<?> firstEvent)
Instantiate the aggregate root using the given aggregate identifier and first event.
|
Class<T> |
getAggregateType()
Returns the type of aggregate this factory creates.
|
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext) |
void |
setBeanName(String beanName) |
static <T> SpringPrototypeAggregateFactory<T> |
withSubtypeSupport(Class<T> aggregateType,
String prototypeBeanName,
Map<Class<? extends T>,String> subtypes)
Initializes the factory to create bean instances from the given
prototypeBeanName or its
subtypes . |
@Deprecated public SpringPrototypeAggregateFactory(String prototypeBeanName)
SpringPrototypeAggregateFactory(Class, String, Map)
to ensure all required
fields are present for both polymorphic and non-polymorphic aggregates.prototypeBeanName
.
Note that the bean should have the prototype scope.
prototypeBeanName
- the name of the prototype bean this repository serves.@Deprecated public SpringPrototypeAggregateFactory(String prototypeBeanName, Map<Class<? extends T>,String> subtypes)
SpringPrototypeAggregateFactory(Class, String, Map)
to ensure all required
fields are present for both polymorphic and non-polymorphic aggregates.prototypeBeanName
and its
subtypes
.
Note that the bean should have the prototype scope.
prototypeBeanName
- the name of the prototype bean this repository serves.subtypes
- the map of subtype of this aggregate to its spring prototype namepublic SpringPrototypeAggregateFactory(Class<T> aggregateType, String prototypeBeanName, Map<Class<? extends T>,String> subtypes)
prototypeBeanName
or its
subtypes
.
Whenever subtypes
is not null, it is expected that the prototypeBeanName
does not exist in
the ApplicationContext
due to the fact that root types are expected to be abstract
. Furthermore,
abstract
classes are not made a part of the ApplicationContext
and as such there cannot be a bean
definition referencing it.
Note that the prototypeBeanName
should have the prototype scope when there are not subtypes
. When
subtypes
are present, all values of the subtypes
collection are expected to be prototype scoped.
aggregateType
- The type of aggregate constructed by this AggregateFactory
. Is the root type of
the aggregate whenever subtypes
is not empty.prototypeBeanName
- The name of the prototype bean this repository serves. When subtypes
isn't
empty, the name is expected to equal the simple name
of
the aggregateType
.subtypes
- The map of subtype of this aggregate to its spring prototype name. @return An
initialized instance of this factory.public static <T> SpringPrototypeAggregateFactory<T> withSubtypeSupport(Class<T> aggregateType, String prototypeBeanName, Map<Class<? extends T>,String> subtypes)
prototypeBeanName
or its
subtypes
.
Whenever subtypes
is not null, it is expected that the prototypeBeanName
does not exist in
the ApplicationContext
due to the fact that root types are expected to be abstract
. Furthermore,
abstract
classes are not made a part of the ApplicationContext
and as such there cannot be a bean
definition referencing it.
Note that the prototypeBeanName
should have the prototype scope when there are not subtypes
. When
subtypes
are present, all values of the subtypes
collection are expected to be prototype scoped.
This static factory method is provided as an alternative to avoid warnings and errors on ambiguous constructor resolution when using Spring AOT.
aggregateType
- The type of aggregate constructed by this AggregateFactory
. Is the root type of
the aggregate whenever subtypes
is not empty.prototypeBeanName
- The name of the prototype bean this repository serves. When subtypes
isn't
empty, the name is expected to equal the simple name
of
the aggregateType
.subtypes
- The map of subtype of this aggregate to its spring prototype name. @return An
initialized instance of this factory.public T createAggregateRoot(String aggregateIdentifier, DomainEventMessage<?> firstEvent)
AggregateFactory
createAggregateRoot
in interface AggregateFactory<T>
aggregateIdentifier
- the aggregate identifier of the aggregate to instantiatefirstEvent
- The first event in the event stream. This is either the event generated during
creation of the aggregate, or a snapshot eventpublic Class<T> getAggregateType()
AggregateFactory
instanceOf
this type.getAggregateType
in interface AggregateFactory<T>
public void setApplicationContext(@Nonnull org.springframework.context.ApplicationContext applicationContext)
setApplicationContext
in interface org.springframework.context.ApplicationContextAware
public void setBeanName(@Nonnull String beanName)
setBeanName
in interface org.springframework.beans.factory.BeanNameAware
public void afterPropertiesSet()
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
Copyright © 2010–2023. All rights reserved.