9using Microsoft.EntityFrameworkCore;
32 [Obsolete(
"Use dependency injection instead",
false)]
35 private static object _lock =
new object();
37 private string _label;
38 private string _contextLabel;
71 var contextLabel = GetContextName(database, label);
74 if (ApplicationContext.LocalContext.Contains(contextLabel))
87 ApplicationContext.LocalContext[contextLabel] = mgr;
96 _contextLabel = GetContextName(database, label);
98 if (
string.IsNullOrEmpty(database))
99 _context = (C)(Activator.CreateInstance(typeof(C)));
101 _context = (C)(Activator.CreateInstance(typeof(C), database));
104 private static string GetContextName(
string database,
string label)
106 return "__dbctx:" + label +
"-" + database;
115 get {
return _context; }
118 private int _refCount;
126 get {
return _refCount; }
129 private void AddRef()
142 ApplicationContext.LocalContext.Remove(_contextLabel);
155 GC.SuppressFinalize(
this);
Provides an automated way to reuse Entity Framework DbContext objects within the context of a single ...
C DbContext
Gets the DbContext object.
static DbContextManager< C > GetManager(string database, string label)
Gets the DbContextManager object for the specified database.
void Dispose()
Dispose object, dereferencing or disposing the context it is managing.
static DbContextManager< C > GetManager()
Gets the DbContextManager object for the /// specified database.
virtual void Dispose(bool p)
Dispose object, dereferencing or disposing the context it is managing.
static DbContextManager< C > GetManager(string database)
Gets the DbContextManager object for the specified database.
int RefCount
Gets the current reference count for this object.