public async Task <T> GetByIdAsync <T>(Guid id) where T : Aggregate, new()
        {
            var isSnapshottable = typeof(ISnapshottable <T>).GetTypeInfo().IsAssignableFrom(typeof(T).GetTypeInfo());

            var aggregate = new T();

            Snapshot snapshot = null;

            if ((isSnapshottable) && (snapshotStore != null))
            {
                snapshot = ((ISnapshottable <T>)aggregate).TakeSnapshot();
                snapshot = await snapshotStore.GetSnapshotAsync <T>(snapshot.GetType(), id);
            }

            //snapshot exists?
            if (snapshot != null)
            {
                Console.WriteLine(snapshot.Id);
                var item = (T)Activator.CreateInstance(typeof(T));

                ((ISnapshottable <T>)item).ApplySnapshot(snapshot);
                Console.WriteLine("getting data from snapshot:" + item.Version);
                var events = await aggregateStore.GetEvents <T>(id.ToString(), snapshot.Version + 1, int.MaxValue);

                Console.WriteLine("load event over snapshot event count:" + events.Length);
                item.Load(events);

                return(item);
            }

            return(await aggregateStore.Load <T>(id.ToString()));
        }
Beispiel #2
0
        private async Task HandleForUpdate(Guid aggregateId, Action <Domain.Review> handle)
        {
            var aggregate = await aggrigateStore.Load <Domain.Review>(aggregateId.ToString());

            handle(aggregate);
            await aggrigateStore.Save(aggregate);
        }