public void Save(TAggregate aggregate) { IAggregateRootInternal <TId> internalAggregate = aggregate; var events = internalAggregate.GetUncommittedEvents().ToList(); int version = aggregate.Version; foreach (IEventInternal @event in events) { @event.SetVersion(++version); } foreach (var eventToStore in events) { _bus.PublishEvent(eventToStore); } var eventsToPublish = internalAggregate.GetUnpublishedEvents(); foreach (IEventInternal @event in eventsToPublish) { @event.SetVersion(version); _bus.PublishEvent((IEvent <TId>)@event); } _eventStore.SaveEvents(aggregate.Id, typeof(TAggregate), events, version, aggregate.Version); internalAggregate.Dispose(); }
public TAggregate Get(TId id) { IAggregateRootInternal <TId> aggregate = _aggregateRootFactory.Create <TAggregate>(); var events = _eventStore.LoadEvents(id, typeof(TAggregate), throwIfNotFound: true).ToList(); aggregate.Load(id, events); return((TAggregate)aggregate); }