public TAggregateRoot Load <TAggregateRoot>(string aggregateRootId, long globalSequenceNumber) where TAggregateRoot : class
        {
            var rootFromCache = GetFromCacheOrNull <TAggregateRoot>(aggregateRootId, globalSequenceNumber);

            if (rootFromCache != null)
            {
                return(rootFromCache);
            }

            // we accept that the root loaded here MIGHT be slightly stale due to fast-track dispatch with in-mem events - therefore
            // we run our in-mem events over the newly hydrated root to give it a chance to apply any of the newly emitted events that might
            // not have been available when we loaded the root from the event store
            var aggregateRoot = LoadAggregateRoot <TAggregateRoot>(aggregateRootId, globalSequenceNumber);

            var entry = new CachedRoot(aggregateRoot, globalSequenceNumber);

            foreach (var e in _eventBatch)
            {
                entry.MaybeApply(e, _realUnitOfWork, globalSequenceNumber);
            }

            _cachedRoots[aggregateRootId] = entry;

            return(aggregateRoot as TAggregateRoot);
        }
Exemple #2
0
        public TAggregateRoot Load <TAggregateRoot>(string aggregateRootId, long globalSequenceNumber) where TAggregateRoot : class
        {
            var rootFromCache = GetFromCacheOrNull <TAggregateRoot>(aggregateRootId, globalSequenceNumber);

            if (rootFromCache != null)
            {
                return(rootFromCache);
            }

            var aggregateRoot = LoadAggregateRoot <TAggregateRoot>(aggregateRootId, globalSequenceNumber);

            _cachedRoots[aggregateRootId] = new CachedRoot(aggregateRoot, globalSequenceNumber);

            return(aggregateRoot as TAggregateRoot);
        }