Minor refactoring (#6939)

This commit is contained in:
Nicolas Dorier
2025-10-07 17:06:26 +09:00
committed by GitHub
parent 5e9dca19d5
commit 84c2caf2c8
8 changed files with 81 additions and 14 deletions

View File

@@ -0,0 +1,21 @@
#nullable enable
using System;
using System.Data.Common;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
namespace BTCPayServer.Data;
public static partial class ApplicationDbContextExtensions
{
public static DbContext GetDbContext<T>(this DbSet<T> dbSet) where T : class
{
var infrastructure = dbSet as IInfrastructure<IServiceProvider>;
var serviceProvider = infrastructure.Instance;
var currentDbContext = (ICurrentDbContext)serviceProvider.GetService(typeof(ICurrentDbContext))!;
return currentDbContext.Context;
}
public static DbConnection GetDbConnection<T>(this DbSet<T> dbSet) where T : class
=> dbSet.GetDbContext().Database.GetDbConnection();
}