Esempio n. 1
0
        public async Task <TAggregate> GetByIdAsync <TAggregate>(Guid id, int version = int.MaxValue)
            where TAggregate : IAggregate, new()
        {
            var memento = await MementoStore.GetMementoAsync(id, version);

            var aggregate = _factory.Build <TAggregate>(memento);

            await ApplyEventsAsync(id, version, aggregate);

            return(aggregate);
        }
Esempio n. 2
0
        private async Task <IAggregateRoot> LoadAggregate(ICommand command)
        {
            var aggregate = _factory.Build(command.Destination);

            if (aggregate is ISupportSnapshots withSnapshots)
            {
                var snapshot = await _snapshotStore.GetSnapshot(command.Destination);

                if (snapshot != null)
                {
                    aggregate = withSnapshots.RestoreFromSnapshot(snapshot);
                }
            }

            await foreach (var e in _eventStore.GetEventStream(aggregate.Address))
            {
                aggregate.Apply(e);
            }

            return(aggregate);
        }
Esempio n. 3
0
 public static T Build <T>(this IAggregateFactory factory, string id = null) where T : IAggregate
 {
     return((T)factory.Build(typeof(T), id ?? Guid.NewGuid().ToString()));
 }
Esempio n. 4
0
 private IAggregate GetAggregate <TAggregate>(IEventStream stream)
 {
     return(_aggregateFactory.Build(typeof(TAggregate), stream.StreamId));
 }