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

            await _eventRepository.AppendAsync(aggregateRoot);

            aggregateRoot.ClearEvents();
        }
Exemplo n.º 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);
        }
Exemplo n.º 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();
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }