예제 #1
0
        public Task <Nothing> AppendAsync(AggregateId aggregateId, IReadOnlyList <IDomainEvent> domainEvents, long expectedVersion)
        {
            if (!_domainEventsPerAggregate.TryGetValue(aggregateId.ToPureAggregateId(), out var aggregateDomainEvents))
            {
                aggregateDomainEvents = new List <IDomainEvent>();
                _domainEventsPerAggregate.Add(aggregateId.ToPureAggregateId(), aggregateDomainEvents);
            }

            PreventAppendIfExpectedVersionDoesntMatchWithNumberOfPreviouslyAppliedEventsForAggregate(
                aggregateId.ToPureAggregateId(),
                expectedVersion,
                aggregateDomainEvents);

            aggregateDomainEvents.AddRange(domainEvents);
            _allDomainEvents.AddRange(domainEvents);

            return(Task.FromResult(NotAtAll));
        }
예제 #2
0
        public Task <IReadOnlyList <IDomainEvent> > AsyncLoadAllEventsFor(AggregateId aggregateId)
        {
            if (!_domainEventsPerAggregate.TryGetValue(aggregateId.ToPureAggregateId(), out var aggregateDomainEvents))
            {
                aggregateDomainEvents = new List <IDomainEvent>();
            }

            return(Task.FromResult(aggregateDomainEvents as IReadOnlyList <IDomainEvent>));
        }