public async Task SaveAsync(TAggregate aggregate)
        {
            try
            {
                IEventSourced <TAggregateId> aggregateEventSourcedView = aggregate;

                foreach (var evt in aggregateEventSourcedView.UncommittedEvents)
                {
                    await _eventStore.AddEventAsync(evt).ConfigureAwait(false);

                    // TODO : create PublishEventAsync method to make this call async
                    PublishEvent(evt);
                }
                aggregateEventSourcedView.ClearUncommittedEvents();
            }
            catch (EventStoreNotReachableException ex)
            {
                throw new RepositoryException(CommunicationImpossibleWithPersistenceBackend, ex);
            }
        }
 public void Save(TAggregate aggregate)
 {
     try
     {
         IEventSourced <TAggregateId> aggregateEventSourcedView = aggregate;
         var  versionFromStore = _eventStore.GetNextExpectedVersion(aggregate.AggregateId);
         long count            = 0;
         foreach (var evt in aggregateEventSourcedView.UncommittedEvents)
         {
             VersionGuard(versionFromStore, evt);
             versionFromStore = _eventStore.AddEvent(evt);
             PublishEvent(evt);
             count++;
         }
         aggregateEventSourcedView.ClearUncommittedEvents();
     }
     catch (EventStoreNotReachableException ex)
     {
         throw new RepositoryException(CommunicationImpossibleWithPersistenceBackend, ex);
     }
 }
        public TAggregate GetById(TAggregateId id)
        {
            try
            {
                var aggregate = _emptyAggregateFactory.GetEmptyAggregate();
                IEventSourced <TAggregateId> aggregateEventSourcedView = aggregate;

                foreach (var evt in _eventStore.ReadEvents(id))
                {
                    //aggregate.RaiseEvent(evt.DomainEvent);
                    aggregateEventSourcedView.ProcessEvent(evt.DomainEvent, evt.Version);
                }
                aggregateEventSourcedView.ClearUncommittedEvents();
                return(aggregate);
            }
            catch (AggregateNotFoundEventStoreException)
            {
                return(null);
            }
            catch (EventStoreNotReachableException ex)
            {
                throw new RepositoryException(CommunicationImpossibleWithPersistenceBackend, ex);
            }
        }