示例#1
0
        public TAggregate Load <TAggregate>(Guid id)
            where TAggregate : AggregateRoot <Guid>
        {
            TAggregate root;
            long       snapshotVersion = 0;

            if (_snapshotRepository != null && _snapshotRepository.TryGetSnapshotById <TAggregate>(id, out root, out snapshotVersion))
            {
                var stream = _eventStore.LoadEventStreamAfterVersion(id, snapshotVersion);

                root.ReplayEvents(stream.Events);

                return(root);
            }
            else
            {
                EventStream stream = _eventStore.LoadEventStream(id);

                return((TAggregate)Activator.CreateInstance(typeof(TAggregate), new object[] { stream }));
            }
        }