public async Task PublishAsync <TAggregate, TIdentity>( TIdentity id, IReadOnlyCollection <IDomainEvent> domainEvents, CancellationToken cancellationToken) where TAggregate : IAggregateRoot <TIdentity> where TIdentity : IIdentity { // ARGH, dilemma, should we pass the cancellation token to read model update or not? var updateReadStoresTasks = _readStoreManagers .Select(rsm => rsm.UpdateReadStoresAsync(domainEvents, CancellationToken.None)); await Task.WhenAll(updateReadStoresTasks).ConfigureAwait(false); // Send to handlers that listen to all events var handle = _subscribeSynchronousToAlls .Select(s => s.HandleAsync(domainEvents, cancellationToken)); await Task.WhenAll(handle).ConfigureAwait(false); // Update subscriptions AFTER read stores have been updated await _dispatchToEventSubscribers.DispatchAsync(domainEvents, cancellationToken).ConfigureAwait(false); // Update sagas await _dispatchToSagas.ProcessAsync(domainEvents, cancellationToken).ConfigureAwait(false); }
private async Task PublishToSagasAsync( IReadOnlyCollection <IDomainEvent> domainEvents, CancellationToken cancellationToken) { await _dispatchToSagas.ProcessAsync(domainEvents, cancellationToken).ConfigureAwait(false); }