示例#1
0
        protected void RaiseEvent(IEvent @event)
        {
            stateModel = EventSourcedState <TState> .LoadState(stateModel, new[] { @event });

            if (@event is IChildEntityEvent &&
                this is IAggregateRoot)
            {
                var aggregateRootState = stateModel as IAggregateRootStateInternal;
                var childEvent         = @event as IChildEntityEvent;

                var originalChildState = aggregateRootState.ChildStates.FirstOrDefault(x => x.Id.Equals(childEvent.Id));

                var childState = originalChildState ?? aggregateRootState.ChildStateCreationMap[@event.GetType()](@event);

                var newState = childState.UntypedApply(@event);

                if (newState != originalChildState)
                {
                    if (originalChildState != null)
                    {
                        aggregateRootState.RemoveChildState(originalChildState);
                    }

                    aggregateRootState.AddChildState((IChildEventSourcedState)newState);
                }
            }

            uncommittedEvents.Add(@event);
            version++;
        }
示例#2
0
        public EventSourcedEntity(IEvent @event, TState initialState = null)
        {
            stateModel = EventSourcedState <TState> .LoadState(initialState, new[] { @event });

            uncommittedEvents.Add(@event);
            version = 1;
        }
示例#3
0
        void IEventSourcedEntity <TState, TKey> .LoadEvents(IEnumerable <IEvent> events, TState initialState)
        {
            committedVersion = version = events.Count();

            stateModel = EventSourcedState <TState> .LoadState(initialState, events);
        }