// this Update method abstracts away the name of the exact aggregate method that we will be using/calling // this approach allows us to use this single Update method for multiple command messages // this method is where we implement the lifetime management of an Aggregate in one place void Update(ICommand <FactoryId> forAggregateIdentifiedBy, Action <FactoryAggregate> executeCommandUsingThis) { // Load the event stream from the event store using the FactoryId of the passed in command var eventStream = _eventStore.LoadEventStream(forAggregateIdentifiedBy.Id); // create a new Factory aggregate instance from its history of allEventsRelatedToThisAggregateId var aggregateState = new FactoryState(eventStream.Events); var aggregate = new FactoryAggregate(aggregateState); // execute the delegated Action (lambda that contains a reference to a specific aggregate method call) // that was passed to this Update method by the "When" methods below executeCommandUsingThis(aggregate); // append resulting changes to the aggregate's event stream _eventStore.AppendEventsToStream(forAggregateIdentifiedBy.Id, eventStream.StreamVersion, aggregate.EventsThatHappened); }
// this Update method abstracts away the name of the exact aggregate method that we will be using/calling // this approach allows us to use this single Update method for multiple command messages // this method is where we implement the lifetime management of an Aggregate in one place void Update(ICommand<FactoryId> forAggregateIdentifiedBy, Action<FactoryAggregate> executeCommandUsingThis) { // Load the event stream from the event store using the FactoryId of the passed in command var eventStream = _eventStore.LoadEventStream(forAggregateIdentifiedBy.Id); // create a new Factory aggregate instance from its history of allEventsRelatedToThisAggregateId var aggregateState = new FactoryState(eventStream.Events); var aggregate = new FactoryAggregate(aggregateState); // execute the delegated Action (lambda that contains a reference to a specific aggregate method call) // that was passed to this Update method by the "When" methods below executeCommandUsingThis(aggregate); // append resulting changes to the aggregate's event stream _eventStore.AppendEventsToStream(forAggregateIdentifiedBy.Id, eventStream.StreamVersion, aggregate.EventsThatHappened); }
public FactoryAggregate(FactoryState aggregateState) { _aggregateState = aggregateState; }