Class SpringPrototypeAggregateFactory<T>

java.lang.Object
org.axonframework.spring.eventsourcing.SpringPrototypeAggregateFactory<T>
Type Parameters:
T - The type of aggregate generated by this aggregate factory.
All Implemented Interfaces:
org.axonframework.eventsourcing.AggregateFactory<T>, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware

public class SpringPrototypeAggregateFactory<T> extends Object implements org.axonframework.eventsourcing.AggregateFactory<T>, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.BeanNameAware
An AggregateFactory implementation that uses Spring prototype beans to create new uninitialized instances of Aggregates.
Since:
1.2
Author:
Allard Buijze
  • Constructor Details

    • SpringPrototypeAggregateFactory

      @Deprecated public 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.
      Initializes the factory to create beans instances for the bean with given prototypeBeanName.

      Note that the bean should have the prototype scope.

      Parameters:
      prototypeBeanName - the name of the prototype bean this repository serves.
    • SpringPrototypeAggregateFactory

      @Deprecated public 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.
      Initializes the factory to create beans instances for the bean with given prototypeBeanName and its subtypes.

      Note that the bean should have the prototype scope.

      Parameters:
      prototypeBeanName - the name of the prototype bean this repository serves.
      subtypes - the map of subtype of this aggregate to its spring prototype name
    • SpringPrototypeAggregateFactory

      public 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.

      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.

      Parameters:
      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.
  • Method Details

    • withSubtypeSupport

      public 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.

      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.

      Parameters:
      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.
    • createAggregateRoot

      public T createAggregateRoot(String aggregateIdentifier, org.axonframework.eventhandling.DomainEventMessage<?> firstEvent)
      Specified by:
      createAggregateRoot in interface org.axonframework.eventsourcing.AggregateFactory<T>
    • getAggregateType

      public Class<T> getAggregateType()
      Specified by:
      getAggregateType in interface org.axonframework.eventsourcing.AggregateFactory<T>
    • setApplicationContext

      public void setApplicationContext(@Nonnull org.springframework.context.ApplicationContext applicationContext)
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
    • setBeanName

      public void setBeanName(@Nonnull String beanName)
      Specified by:
      setBeanName in interface org.springframework.beans.factory.BeanNameAware
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean