public static DataContextScope GetCurrent(string connectionName = null) { if (string.IsNullOrEmpty(connectionName)) { connectionName = DefaultConnectionName; } var key = KeyPrefix + connectionName; DataContextScope ctx = null; if (HttpContext.Current != null) { ctx = HttpContext.Current.Items[key] as DataContextScope; if (ctx == null) { ctx = new DataContextScope(connectionName); HttpContext.Current.Items[key] = ctx; } } else { LocalDataStoreSlot slot = Thread.GetNamedDataSlot(key); ctx = Thread.GetData(slot) as DataContextScope; if (ctx == null) { ctx = new DataContextScope(connectionName); Thread.SetData(slot, ctx); } } return ctx; }
public static DataContextScope GetCurrent(string connectionName = null) { if (string.IsNullOrEmpty(connectionName)) { connectionName = DefaultConnectionName; } var key = KeyPrefix + connectionName; DataContextScope ctx = null; if (HttpContext.Current != null) { ctx = HttpContext.Current.Items[key] as DataContextScope; if (ctx == null) { ctx = new DataContextScope(connectionName); HttpContext.Current.Items[key] = ctx; } } else { LocalDataStoreSlot slot = Thread.GetNamedDataSlot(key); ctx = Thread.GetData(slot) as DataContextScope; if (ctx == null) { ctx = new DataContextScope(connectionName); Thread.SetData(slot, ctx); } } return(ctx); }
public static DataContextScope GetCurrent(string connectionName = null) { if (string.IsNullOrEmpty(connectionName)) { connectionName = DefaultConnectionName; } var key = KeyPrefix + connectionName; DataContextScope ctx = null; #if NETCOREAPP2_1 || NETSTANDARD ctx = Local.Value; if (ctx == null) { ctx = new UnitOfWork(connectionName); Local.Value = ctx; } return(ctx); #elif NET if (HttpContext.Current != null) { ctx = HttpContext.Current.Items[key] as UnitOfWork; if (ctx == null) { ctx = new UnitOfWork(connectionName); HttpContext.Current.Items[key] = ctx; } return(ctx); } else { ctx = Local.Value; if (ctx == null) { ctx = new UnitOfWork(connectionName); Local.Value = ctx; } return(ctx); } #endif return(ctx); }