Interface AggregateFactory<T>

Type Parameters:
T - The type of aggregate this factory creates
All Known Implementing Classes:
AbstractAggregateFactory, GenericAggregateFactory, SpringPrototypeAggregateFactory

public interface AggregateFactory<T>
Interface describing objects capable of creating instances of aggregates to be initialized with an event stream.

Implementation note: to make sure an implementation handles snapshot events correctly, consider extending AbstractAggregateFactory.

Since:
0.6
Author:
Allard Buijze
  • Method Summary

    Modifier and Type
    Method
    Description
    createAggregateRoot(String aggregateIdentifier, DomainEventMessage<?> firstEvent)
    Instantiate the aggregate root using the given aggregate identifier and first event.
    Returns the type of aggregate this factory creates.
  • Method Details

    • createAggregateRoot

      T createAggregateRoot(String aggregateIdentifier, DomainEventMessage<?> firstEvent)
      Instantiate the aggregate root using the given aggregate identifier and first event. The first event of the event stream is passed to allow the factory to identify the actual implementation type of the aggregate to create. The first event can be either the event that created the aggregate or, when using event sourcing, a snapshot event. In either case, the event should be designed, such that these events contain enough information to deduct the actual aggregate type.
      Parameters:
      aggregateIdentifier - the aggregate identifier of the aggregate to instantiate
      firstEvent - The first event in the event stream. This is either the event generated during creation of the aggregate, or a snapshot event
      Returns:
      an aggregate root ready for initialization using a DomainEventStream.
    • getAggregateType

      Class<T> getAggregateType()
      Returns the type of aggregate this factory creates. All instances created by this factory must be an instanceOf this type.
      Returns:
      The type of aggregate created by this factory