void Update(ICommand<FactoryId> c, Action<FactoryAggregate> execute) { // Load event stream from the store var eventStream = _eventStore.LoadEventStream(c.Id); // create new Factory aggregate from the history var state = new FactoryState(eventStream.Events); var agg = new FactoryAggregate(state); // execute delegated action execute(agg); // append resulting changes to the stream _eventStore.AppendEventsToStream(c.Id, eventStream.StreamVersion, agg.Changes); }
void Update(ICommand <FactoryId> c, Action <FactoryAggregate> execute) { // Load event stream from the store var eventStream = _eventStore.LoadEventStream(c.Id); // create new Factory aggregate from the history var state = new FactoryState(eventStream.Events); var agg = new FactoryAggregate(state); // execute delegated action execute(agg); // append resulting changes to the stream _eventStore.AppendEventsToStream(c.Id, eventStream.StreamVersion, agg.Changes); }
// 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 a FactoryAggregate in one place void Update(ICommand <FactoryId> c, Action <FactoryAggregate> execute) { // Load the event stream from the store using the FactoryId of the passed in command var eventStream = _eventStore.LoadEventStream(c.Id); // create a new Factory aggregate instance from its history of events var state = new FactoryState(eventStream.Events); var agg = new FactoryAggregate(state); // execute the delegated Action (lambda that contains a reference to a specific method call) // that was passed to this Update method by the "When" methods below execute(agg); // append resulting changes to the aggregate state to the event stream _eventStore.AppendEventsToStream(c.Id, eventStream.StreamVersion, agg.Changes); }
// 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 a FactoryAggregate in one place void Update(ICommand<FactoryId> c, Action<FactoryAggregate> execute) { // Load the event stream from the store using the FactoryId of the passed in command var eventStream = _eventStore.LoadEventStream(c.Id); // create a new Factory aggregate instance from its history of events var state = new FactoryState(eventStream.Events); var agg = new FactoryAggregate(state); // execute the delegated Action (lambda that contains a reference to a specific method call) // that was passed to this Update method by the "When" methods below execute(agg); // append resulting changes to the aggregate state to the event stream _eventStore.AppendEventsToStream(c.Id, eventStream.StreamVersion, agg.Changes); }
public FactoryAggregate(FactoryState state) { _state = state; }
// 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; }