コード例 #1
0
        public async Task <IEnumerable <DomainEventResult> > AppendAsync(
            IEnumerable <IDomainEvent> events,
            CancellationToken token = default)
        {
            if (events.IsEmpty())
            {
                return(Enumerable.Empty <DomainEventResult>());
            }

            var results = new List <DomainEventResult>();

            foreach (var @event in events)
            {
                _dict.AddOrUpdate(@event.AggregateRootId, new List <IDomainEvent>()
                {
                    @event
                },
                                  (key, oldValue) =>
                {
                    oldValue.Add(@event);
                    return(oldValue);
                });

                results.Add(DomainEventResult.StorageSucceed(@event.Id));
            }

            return(await Task.FromResult(results));
        }
コード例 #2
0
        public async Task <DomainEventResult> AppendAsync(
            IDomainEvent @event,
            CancellationToken token = default)
        {
            if (@event == null)
            {
                return(await Task.FromResult(DomainEventResult.StorageSucceed(@event.Id)));
            }

            _dict.AddOrUpdate(@event.AggregateRootId, new List <IDomainEvent>()
            {
                @event
            },
                              (key, oldValue) =>
            {
                oldValue.Add(@event);
                return(oldValue);
            });

            return(await Task.FromResult(DomainEventResult.StorageSucceed(@event.Id)));
        }