public async Task <Maybe <TAggregate> > GetByIdAsync(TAggregateId id) { try { var aggregate = CreateEmptyAggregate(); IEventSourcingAggregate <TAggregateId> aggregatePersistence = aggregate; foreach (var @event in await eventStore.ReadEventsAsync(id)) { aggregatePersistence.ApplyEvent(@event.DomainEvent, @event.EventNumber); } if (aggregate == null) { return(Maybe <TAggregate> .None); } return(aggregate); } catch (EventStoreAggregateNotFoundException) { return(null); } catch (EventStoreCommunicationException ex) { throw new RepositoryException("Unable to access persistence layer", ex); } }
public async Task <TAggregate> GetByIdAsync(TAggregateId id) { var aggregate = CreateEmptyAggregate(); IEventSourcingAggregate <TAggregateId> aggregatePersistence = aggregate; foreach (var @event in await eventStore.ReadEventsAsync(id)) { aggregatePersistence.ApplyEvent(@event.DomainEvent, @event.EventNumber); } return(aggregate); }