mirror of https://github.com/abpframework/abp.git
4 changed files with 46 additions and 39 deletions
@ -0,0 +1,28 @@ |
|||||
|
using System; |
||||
|
using System.Threading; |
||||
|
|
||||
|
namespace Volo.Abp.EntityFrameworkCore.DependencyInjection |
||||
|
{ |
||||
|
internal class DbContextCreationContext |
||||
|
{ |
||||
|
public static DbContextCreationContext Current => _current.Value; |
||||
|
private static readonly AsyncLocal<DbContextCreationContext> _current = new AsyncLocal<DbContextCreationContext>(); |
||||
|
|
||||
|
public string ConnectionStringName { get; } |
||||
|
|
||||
|
public string ConnectionString { get; } |
||||
|
|
||||
|
public DbContextCreationContext(string connectionStringName, string connectionString) |
||||
|
{ |
||||
|
ConnectionStringName = connectionStringName; |
||||
|
ConnectionString = connectionString; |
||||
|
} |
||||
|
|
||||
|
public static IDisposable Use(DbContextCreationContext context) |
||||
|
{ |
||||
|
var previousValue = Current; |
||||
|
_current.Value = context; |
||||
|
return new DisposeAction(() => _current.Value = previousValue); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,27 +0,0 @@ |
|||||
using System; |
|
||||
using System.Threading; |
|
||||
|
|
||||
namespace Volo.Abp.EntityFrameworkCore.DependencyInjection |
|
||||
{ |
|
||||
internal class DbContextOptionsFactoryContext |
|
||||
{ |
|
||||
public static DbContextOptionsFactoryContext Current => _current.Value; |
|
||||
private static readonly AsyncLocal<DbContextOptionsFactoryContext> _current = new AsyncLocal<DbContextOptionsFactoryContext>(); |
|
||||
|
|
||||
public string ConnectionStringName { get; } |
|
||||
|
|
||||
public string ConnectionString { get; } |
|
||||
|
|
||||
public DbContextOptionsFactoryContext(string connectionStringName, string connectionString) |
|
||||
{ |
|
||||
ConnectionStringName = connectionStringName; |
|
||||
ConnectionString = connectionString; |
|
||||
} |
|
||||
|
|
||||
public static IDisposable Use(DbContextOptionsFactoryContext context) |
|
||||
{ |
|
||||
_current.Value = context; |
|
||||
return new DisposeAction(() => _current.Value = null); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue