public async Task SendQuery <T>(ConsumeContext <T> context, ISagaQuery <TSaga> query, IPipe <SagaRepositoryQueryContext <TSaga, T> > next)
            where T : class
        {
            var dbContext = _dbContextFactory.CreateScoped(context);

            try
            {
                var lockContext = await _lockStrategy.CreateLockContext(dbContext, query, context.CancellationToken).ConfigureAwait(false);

                var repositoryContext = new DbContextSagaRepositoryContext <TSaga, T>(dbContext, context, _consumeContextFactory, _lockStrategy);

                await WithinTransaction(dbContext, async() =>
                {
                    var instances = await lockContext.Load().ConfigureAwait(false);

                    var queryContext = new LoadedSagaRepositoryQueryContext <TSaga, T>(repositoryContext, instances);

                    await next.Send(queryContext).ConfigureAwait(false);
                }).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, async() =>
                {
                    using var repositoryContext = new DbContextSagaRepositoryContext <TSaga, T>(dbContext, context, _consumeContextFactory, _lockStrategy);

                    await next.Send(repositoryContext).ConfigureAwait(false);
                }).ConfigureAwait(false);
            }
        public async Task <T> Execute <T>(Func <SagaRepositoryContext <TSaga>, Task <T> > asyncMethod, CancellationToken cancellationToken = default)
            where T : class
        {
            var dbContext = _dbContextFactory.Create();

            try
            {
                return(await WithinTransaction(dbContext, () =>
                {
                    var sagaRepositoryContext = new DbContextSagaRepositoryContext <TSaga>(dbContext, cancellationToken);

                    return asyncMethod(sagaRepositoryContext);
                }).ConfigureAwait(false));
            }
            finally
            {
                _dbContextFactory.Release(dbContext);
            }
        }