// 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(IFactoryCommand forAggregateIdentifiedBy, Action<FactoryAggregate> executeCommandUsingThis)
        {
            // Load the event stream from the event store using the FactoryId of the passed in command
            var key = forAggregateIdentifiedBy.Id.ToString();
            var eventStream = _eventStore.LoadEventStream(key);

            // 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(key, eventStream.StreamVersion, aggregate.EventsThatHappened);
        }
Esempio n. 2
0
        // 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(IFactoryCommand forAggregateIdentifiedBy, Action <FactoryAggregate> executeCommandUsingThis)
        {
            // Load the event stream from the event store using the FactoryId of the passed in command
            var key         = forAggregateIdentifiedBy.Id.ToString();
            var eventStream = _eventStore.LoadEventStream(key);

            // 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(key, eventStream.StreamVersion, aggregate.EventsThatHappened);
        }
Esempio n. 3
0
 public FactoryAggregate(FactoryState aggregateState)
 {
     _aggregateState = aggregateState;
 }
Esempio n. 4
0
 public FactoryAggregate(FactoryState aggregateState)
 {
     _aggregateState = aggregateState;
 }