Exemple #1
0
        public virtual T GetByID(Guid id)
        {
            T aggregate = aggregate_factory_.CreateAggregate(id);
            ICollection <Event> events = storage_.GetEventsForAggregate(id, serialzer_);

            aggregate.LoadFromHistory(events);
            return(aggregate);
        }
        public async Task <T> Get <T>(string aggregateId, CancellationToken cancellationToken = default) where T : AggregateRoot
        {
            _logger.Debug(() => $"Initializing aggregate of type {typeof(T).Name} with id {aggregateId}");
            var aggregate = _aggregateFactory.CreateAggregate <T>();

            aggregate.Id = aggregateId;
            var eventStream = await _eventStore.GetEventStream(aggregateId, AggregateRoot.InitialVersion + 1, cancellationToken);

            aggregate.Load(eventStream.Events);
            return(aggregate);
        }
Exemple #3
0
 public Task <T> Get <T>(string aggregateId, CancellationToken cancellationToken = default) where T : AggregateRoot
 => !_snapshotStrategy.IsSnapshottable(typeof(T))
         ? _decoratedRepository.Get <T>(aggregateId, cancellationToken)
 : LoadFromSnapshot(aggregateId, _aggregateFactory.CreateAggregate <T>(), cancellationToken);