public async Task UpdateReadStoresAsync( IReadOnlyCollection <IDomainEvent> domainEvents, CancellationToken cancellationToken) { var relevantDomainEvents = domainEvents .Where(e => AggregateEventTypes.Contains(e.EventType)) .ToList(); if (!relevantDomainEvents.Any()) { Log.Verbose(() => string.Format( "None of these events was relevant for read model '{0}', skipping update: {1}", ReadModelType.Name, string.Join(", ", domainEvents.Select(e => e.EventType.Name)) )); return; } Log.Verbose(() => string.Format( "Updating read model '{0}' in store '{1}' with these events: {2}", typeof(TReadModel).PrettyPrint(), typeof(TReadModelStore).PrettyPrint(), string.Join(", ", relevantDomainEvents.Select(e => e.ToString())))); var readModelContext = new ReadModelContext(); var readModelUpdates = BuildReadModelUpdates(relevantDomainEvents); await ReadModelStore.UpdateAsync( readModelUpdates, readModelContext, UpdateAsync, cancellationToken) .ConfigureAwait(false); }
public async Task UpdateReadStoresAsync( IReadOnlyCollection <IDomainEvent> domainEvents, CancellationToken cancellationToken) { var relevantDomainEvents = domainEvents .Where(e => AggregateEventTypes.Contains(e.EventType)) .ToList(); if (!relevantDomainEvents.Any()) { if (Logger.IsEnabled(LogLevel.Trace)) { Logger.LogTrace( "None of these events was relevant for read model {ReadModelType}, skipping update: {DomainEventTypes}", StaticReadModelType.PrettyPrint(), domainEvents.Select(e => e.EventType.PrettyPrint()).ToList()); } return; } if (Logger.IsEnabled(LogLevel.Trace)) { Logger.LogTrace( "Updating read model {ReadModelType} in store {ReadModelStoreType} with these events: {DomainEventTypes}", StaticReadModelType.PrettyPrint(), typeof(TReadModelStore).PrettyPrint(), relevantDomainEvents.Select(e => e.ToString())); } var contextFactory = new ReadModelContextFactory(ServiceProvider); var readModelUpdates = BuildReadModelUpdates(relevantDomainEvents); if (!readModelUpdates.Any()) { if (Logger.IsEnabled(LogLevel.Trace)) { Logger.LogTrace( "No read model updates after building for read model {ReadModelType} in store {ReadModelStoreType} with these events: {DomainEventTypes}", StaticReadModelType.PrettyPrint(), typeof(TReadModelStore).PrettyPrint(), relevantDomainEvents.Select(e => e.ToString()).ToList()); } return; } await ReadModelStore.UpdateAsync( readModelUpdates, contextFactory, UpdateAsync, cancellationToken) .ConfigureAwait(false); }