public async Task Send <T>(ConsumeContext <T> context, IPipe <SagaRepositoryContext <TSaga, T> > next) where T : class { var dbContext = _dbContextFactory.CreateScoped(context); try { Task Send() => WithinTransaction(dbContext, context.CancellationToken, () => { var repositoryContext = new DbContextSagaRepositoryContext <TSaga, T>(dbContext, context, _consumeContextFactory, _lockStrategy); return(next.Send(repositoryContext)); }); var executionStrategy = dbContext.Database.CreateExecutionStrategy(); if (executionStrategy is ExecutionStrategy) { await executionStrategy.ExecuteAsync(Send).ConfigureAwait(false); } else { await Send().ConfigureAwait(false); } } finally { _dbContextFactory.Release(dbContext); } }
public async Task Send <T>(ConsumeContext <T> context, IPipe <SagaRepositoryContext <TSaga, T> > next) where T : class { var dbContext = _dbContextFactory.CreateScoped(context); try { await WithinTransaction(dbContext, () => { var repositoryContext = new DbContextSagaRepositoryContext <TSaga, T>(dbContext, context, _consumeContextFactory, _lockStrategy); return(next.Send(repositoryContext)); }).ConfigureAwait(false); } finally { _dbContextFactory.Release(dbContext); } }