public async Task <TView> ApplyAsync(TView view, IEvent @event, CancellationToken cancellationToken = default) { if (cancellationToken.IsCancellationRequested) { _logger.LogInformation($"{nameof(InMemoryProjector<TView>)}.{nameof(ApplyAsync)} was cancelled before execution"); cancellationToken.ThrowIfCancellationRequested(); } var subject = Guid.NewGuid().ToString(); var writer = await InMemoryProjectionWriter <TView> .BuildAsync(subject, view, cancellationToken); var manager = _projectionManagerFactory.Create(writer); await manager.HandleAsync(@event, cancellationToken); return(await writer.RetrieveAsync(subject, cancellationToken)); }
public async Task <TView> ProjectAsync(string subject, DateTimeOffset timestamp, CancellationToken cancellationToken = default) { if (cancellationToken.IsCancellationRequested) { _logger.LogInformation($"{nameof(InMemoryProjector<TView>)}.{nameof(ProjectAsync)} was cancelled before execution"); cancellationToken.ThrowIfCancellationRequested(); } var events = await _eventStore.GetEventsAsync(StreamId.From(subject), timestamp, cancellationToken); var writer = await InMemoryProjectionWriter <TView> .BuildAsync(cancellationToken); var manager = _projectionManagerFactory.Create(writer); foreach (var @event in events) { await manager.HandleAsync(@event.Payload, cancellationToken); } return(await writer.RetrieveAsync(subject, cancellationToken)); }