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); } }
public void Save(Account account) { IMemento memento = ((IAggregate)account).GetSnapshot(); documentStore.Save(memento.Identity.GetSurrogateId(), memento); }