Inheritance: IHandleAccountStateTransitions
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
 public void Save(Account account)
 {
     IMemento memento = ((IAggregate)account).GetSnapshot();
     documentStore.Save(memento.Identity.GetSurrogateId(), memento);
 }