public TDbContext Get <TDbContext>() where TDbContext : DbContext { var ambientDbContextScope = DbContextScope.GetAmbientScope(); return(ambientDbContextScope == null ? null : ambientDbContextScope.DbContexts.Get <TDbContext>()); }
public void Dispose() { if (_disposed) { return; } if (_savedScope != null) { DbContextScope.SetAmbientScope(_savedScope); _savedScope = null; } _disposed = true; }
internal static void SetAmbientScope(DbContextScope newAmbientScope) { if (newAmbientScope == null) { throw new ArgumentNullException(nameof(newAmbientScope)); } var current = CallContext.LogicalGetData(AmbientDbContextScopeKey) as InstanceIdentifier; if (current == newAmbientScope._instanceIdentifier) { return; } CallContext.LogicalSetData(AmbientDbContextScopeKey, newAmbientScope._instanceIdentifier); DbContextScopeInstance.GetValue(newAmbientScope._instanceIdentifier, key => newAmbientScope); }
public AmbientContextSuppressor() { _savedScope = DbContextScope.GetAmbientScope(); DbContextScope.HideAmbientScope(); }
public DbContextReadOnlyScope(DbContextScopeOption joiningOption, IsolationLevel?isolationLevel, IDbContextFactory dbContextFactory = null) { _internalScope = new DbContextScope(joiningOption, true, isolationLevel); }