Class GenericAggregateFactory<T>

java.lang.Object
org.axonframework.eventsourcing.AbstractAggregateFactory<T>
org.axonframework.eventsourcing.GenericAggregateFactory<T>
Type Parameters:
T - The type of aggregate this factory creates
All Implemented Interfaces:
AggregateFactory<T>

public class GenericAggregateFactory<T> extends AbstractAggregateFactory<T>
Aggregate factory that uses a convention to create instances of aggregates. The type must declare a no-arg constructor accepting.

If the constructor is not accessible (not public), and the JVM's security setting allow it, the GenericAggregateFactory will try to make it accessible. If that doesn't succeed, an exception is thrown.

Since:
0.7
Author:
Allard Buijze
  • Constructor Details

    • GenericAggregateFactory

      public GenericAggregateFactory(Class<T> aggregateType)
      Initialize the AggregateFactory for creating instances of the given aggregateType.
      Parameters:
      aggregateType - The type of aggregate this factory creates instances of.
      Throws:
      IncompatibleAggregateException - if the aggregate constructor throws an exception, or if the JVM security settings prevent the GenericAggregateFactory from calling the constructor.
    • GenericAggregateFactory

      public GenericAggregateFactory(AggregateModel<T> aggregateModel)
      Initialize the AggregateFactory for creating instances of the given aggregateModel.
      Parameters:
      aggregateModel - the model of aggregate this factory creates instances of
  • Method Details

    • doCreateAggregate

      protected T doCreateAggregate(String aggregateIdentifier, DomainEventMessage firstEvent)
      Create an uninitialized Aggregate instance with the given aggregateIdentifier. The given firstEvent can be used to define the requirements of the aggregate to create.

      The given firstEvent is never a snapshot event.

      Specified by:
      doCreateAggregate in class AbstractAggregateFactory<T>
      Parameters:
      aggregateIdentifier - The identifier of the aggregate to create
      firstEvent - The first event in the Event Stream of the Aggregate
      Returns:
      The aggregate instance to initialize with the Event Stream
      Throws:
      IncompatibleAggregateException - if the aggregate constructor throws an exception, or if the JVM security settings prevent the GenericAggregateFactory from calling the constructor.