private async Task InTransactionAsync(Func <ISqlStorage, CancellationToken, Task> operation, IsolationLevel isolationLevel, CancellationToken cancellationToken)
        {
            await using var context = createDbContext();

            async Task PerformOperation(CancellationToken ct)
            {
                await using var transaction = await context.Database.BeginTransactionAsync(isolationLevel, cancellationToken).ConfigureAwait(false);

                var storage = new SqlStorageInternal(() => context, metricContext, disposeContextOnOperationFinish: false);

                await operation(storage, ct).ConfigureAwait(false);

                await transaction.CommitAsync(ct).ConfigureAwait(false);
            }

            await context.Database.CreateExecutionStrategy().ExecuteAsync(PerformOperation, cancellationToken).ConfigureAwait(false);
        }
 public ConcurrentSqlStorage(Func <SqlDbContext> createDbContext, IMetricContext?metricContext = null)
 {
     this.createDbContext = createDbContext;
     this.metricContext   = metricContext;
     internalStorage      = new SqlStorageInternal(createDbContext, metricContext, disposeContextOnOperationFinish: true);
 }