public async Task PersistAsync(TType aggregateRoot)
        {
            // Dispatch the events and then commit the data.
            await _eventProducer.DispatchAsync(aggregateRoot);

            await _eventRepository.AppendAsync(aggregateRoot);

            aggregateRoot.ClearEvents();
        }
예제 #2
0
        private async Task PersistEventsAsync(
            TAggregate aggregate,
            CancellationToken cancellationToken = default)
        {
            await _eventsRepository.AppendAsync(aggregate, cancellationToken)
            .ConfigureAwait(false);

            await _eventProducer.DispatchAsync(aggregate, cancellationToken)
            .ConfigureAwait(false);
        }
예제 #3
0
        public async Task PersistAsync(TType aggregateRoot)
        {
            // Info: Here we have decoupled the raising of domain events
            // and persiting the aggregate. The event raising and handling is
            // also decoupled and handled by TType events consumers.
            // E.g Order aggregate events (OrderCreated)

            // Dispatch the events and then commit the data.
            await _eventProducer.DispatchAsync(aggregateRoot);

            await _eventRepository.AppendAsync(aggregateRoot);

            aggregateRoot.ClearEvents();
        }
예제 #4
0
        public async Task PersistAsync(TA aggregateRoot)
        {
            if (null == aggregateRoot)
            {
                throw new ArgumentNullException(nameof(aggregateRoot));
            }

            if (!aggregateRoot.Events.Any())
            {
                return;
            }

            await _eventsRepository.AppendAsync(aggregateRoot);

            await _eventProducer.DispatchAsync(aggregateRoot);
        }
예제 #5
0
        public async Task PersistAsync(TA aggregateRoot)
        {
            if (null == aggregateRoot)
            {
                throw new ArgumentNullException(nameof(aggregateRoot));
            }

            if (!aggregateRoot.Events.Any())
            {
                return;
            }

            // Append the aggregate to the eventstore db
            await _eventsRepository.AppendAsync(aggregateRoot);

            // Dispatch the aggregate events to the event bus (Kafka)
            await _eventProducer.DispatchAsync(aggregateRoot);
        }