/// <summary>
        /// 从存储设备中查找一个聚合根
        /// </summary>
        private T GetFromStorage(string aggregateRootId)
        {
            T    aggregateRoot   = null;
            long maxEventVersion = long.MaxValue;
            long minEventVersion = long.MinValue;

            //尝试从快照获取聚合根
            bool success = TryGetFromSnapshot(aggregateRootId, maxEventVersion, out aggregateRoot);

            //如果从快照获取不成功,则尝试从第一个事件开始重演所有事件从而得到聚合根
            if (!success)
            {
                var allCommittedEvents = _eventStoreProvider.GetEventStore <T>().GetEvents(aggregateRootId, minEventVersion, maxEventVersion);
                aggregateRoot = BuildAggregateRootFromCommittedEvents(allCommittedEvents);
            }

            //最后返回聚合根
            return(aggregateRoot);
        }
Esempio n. 2
0
 public void PersistEvents(IEnumerable <AggregateRootEvent> aggregateRootEvents)
 {
     eventStoreProvider.GetEventStore <TAggregateRoot>().StoreEvents(aggregateRootEvents);
 }