public Task <T> Execute <T>(Func <SagaRepositoryContext <TSaga>, Task <T> > asyncMethod, CancellationToken cancellationToken) where T : class { var repositoryContext = new InMemorySagaRepositoryContext <TSaga>(_sagas, cancellationToken); return(asyncMethod(repositoryContext)); }
public async Task Send <T>(ConsumeContext <T> context, IPipe <SagaRepositoryContext <TSaga, T> > next) where T : class { await _sagas.MarkInUse(context.CancellationToken).ConfigureAwait(false); using var repositoryContext = new InMemorySagaRepositoryContext <TSaga, T>(_sagas, _factory, context); await next.Send(repositoryContext).ConfigureAwait(false); }
public async Task SendQuery <T>(ConsumeContext <T> context, ISagaQuery <TSaga> query, IPipe <SagaRepositoryQueryContext <TSaga, T> > next) where T : class { await _sagas.MarkInUse(context.CancellationToken).ConfigureAwait(false); using var repositoryContext = new InMemorySagaRepositoryContext <TSaga, T>(_sagas, _factory, context); var matchingInstances = _sagas.Where(query).Select(x => x.Instance.CorrelationId).ToList(); var queryContext = new DefaultSagaRepositoryQueryContext <TSaga, T>(repositoryContext, matchingInstances); await next.Send(queryContext).ConfigureAwait(false); }