private async Task ProcessAsync( ICommandBus commandBus, IDomainEvent domainEvent, CancellationToken cancellationToken) { var sagaTypeDetails = _sagaDefinitionService.GetSagaDetails(domainEvent.EventType); _log.Verbose(() => $"Saga types to process for domain event '{domainEvent.EventType.PrettyPrint()}': {string.Join(", ", sagaTypeDetails.Select(d => d.SagaType.PrettyPrint()))}"); foreach (var details in sagaTypeDetails) { var locator = (ISagaLocator)_resolver.Resolve(details.SagaLocatorType); var sagaId = await locator.LocateSagaAsync(domainEvent, cancellationToken).ConfigureAwait(false); if (sagaId == null) { _log.Verbose(() => $"Saga locator '{details.SagaLocatorType.PrettyPrint()}' returned null"); continue; } var saga = await ProcessSagaAsync(domainEvent, sagaId, details, cancellationToken).ConfigureAwait(false); if (saga != null) { await saga.PublishAsync(commandBus, cancellationToken).ConfigureAwait(false); } } }
private async Task ProcessAsync( IDomainEvent domainEvent, CancellationToken cancellationToken) { var sagaTypeDetails = _sagaDefinitionService.GetSagaDetails(domainEvent.EventType); if (_logger.IsEnabled(LogLevel.Trace)) { _logger.LogTrace( "Saga types to process for domain event {DomainEventType}: {SagaTypes}", domainEvent.EventType.PrettyPrint(), sagaTypeDetails.Select(d => d.SagaType.PrettyPrint())); } foreach (var details in sagaTypeDetails) { var locator = (ISagaLocator)_serviceProvider.GetRequiredService(details.SagaLocatorType); var sagaId = await locator.LocateSagaAsync(domainEvent, cancellationToken).ConfigureAwait(false); if (sagaId == null) { _logger.LogTrace( "Saga locator {SagaLocatorType} returned null", details.SagaLocatorType.PrettyPrint()); continue; } await ProcessSagaAsync(domainEvent, sagaId, details, cancellationToken).ConfigureAwait(false); } }