org.axonframework.eventsourcing
Interface AggregateFactory<T extends EventSourcedAggregateRoot>

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

public interface AggregateFactory<T extends EventSourcedAggregateRoot>

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, extends the AbstractAggregateFactory instead.

Since:
0.6
Author:
Allard Buijze

Method Summary
 T createAggregate(Object aggregateIdentifier, DomainEventMessage<?> firstEvent)
          Instantiate the aggregate using the given aggregate identifier and first event.
 Class<T> getAggregateType()
          Returns the type of aggregate this factory creates.
 String getTypeIdentifier()
          Returns the type identifier for this aggregate factory.
 

Method Detail

createAggregate

T createAggregate(Object aggregateIdentifier,
                  DomainEventMessage<?> firstEvent)
Instantiate the aggregate 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 ready for initialization using a DomainEventStream.

getTypeIdentifier

String getTypeIdentifier()
Returns the type identifier for this aggregate factory. The type identifier is used by the EventStore to organize data related to the same type of aggregate.

Tip: in most cases, the simple class name would be a good start.

Returns:
the type identifier of the aggregates this repository stores

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


Copyright © 2010-2016. All Rights Reserved.