mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2026-02-22 06:34:36 +01:00
Minor refactoring (#6939)
This commit is contained in:
21
BTCPayServer.Data/ApplicationDbContextExtensions.cs
Normal file
21
BTCPayServer.Data/ApplicationDbContextExtensions.cs
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user