Inheritance: IHandleAccountStateTransitions
示例#1
0
        public void Save(Account account)
        {
            IEnumerable<IDomainEvent> changes = ((IAggregate)account).GetChanges();
            Guid id = ((IHaveIdentity)account.Identity).GetSurrogateId();
            IEventStream eventStream = eventStore.OpenStream(id);

            foreach (var domainEvent in changes)
            {
                if (eventStream.StreamRevision != (domainEvent.Version - 1))
                {
                    throw new Exception(
                        String.Format("Concurrency violation. Expected stream revision {0}, but actual revision was {1}",
                        domainEvent.Version, eventStream.StreamRevision));
                }

                eventStream.Add(new EventMessage(domainEvent));
                eventPublisher.Publish(domainEvent);
            }
        }
示例#2
0
 public void Save(Account account)
 {
     IMemento memento = ((IAggregate)account).GetSnapshot();
     documentStore.Save(memento.Identity.GetSurrogateId(), memento);
 }