Пример #1
0
        public async Task <T> GetByIdAsync <T>(Guid id, long version) where T : AggregateRoot
        {
            var type = typeof(T);
            IEnumerable <Event> events = null;

            logger.Info("[Repository->GetByIdAsync] Retrieving aggregate {0}", id);
            var snapshot = await snapshopStore.GetByIdAsync <T>(id);

            if (snapshot != null)
            {
                logger.Info("[Repository->GetByIdAsync] Snapshot found.");
                events = await eventStore.LoadByMaxVersionAsync <T>(id, snapshot.Version, version);
            }
            else
            {
                logger.Info("[Repository->GetByIdAsync] Snapshot not found.");
                events = await eventStore.LoadByMaxVersionAsync <T>(id, version);
            }

            logger.Info("[Repository->GetByIdAsync] Hydrating Aggregate.");
            var aggregate = BuildAggregate <T>(id, snapshot, events);

            logger.Info("[Repository->GetByIdAsync] Hydratation Completed");

            return(aggregate);
        }