public async Task PersistAsync(TType aggregateRoot) { // Dispatch the events and then commit the data. await _eventProducer.DispatchAsync(aggregateRoot); await _eventRepository.AppendAsync(aggregateRoot); aggregateRoot.ClearEvents(); }
private async Task PersistEventsAsync( TAggregate aggregate, CancellationToken cancellationToken = default) { await _eventsRepository.AppendAsync(aggregate, cancellationToken) .ConfigureAwait(false); await _eventProducer.DispatchAsync(aggregate, cancellationToken) .ConfigureAwait(false); }
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(); }
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); }
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); }