internal static SEDbContext GetDbContext(string name) { SEDbContextConfig dbContextConfig = null; if (string.IsNullOrEmpty(name)) { name = "default"; dbContextConfig = _dbContextConfigMap.FirstOrDefault().Value; } else if (!_dbContextConfigMap.TryGetValue(name, out dbContextConfig)) { throw new KeyNotFoundException(nameof(name)); } if (_asyncLocalStorge.Value == null || _asyncLocalStorge.Value.Count() == 0) { _asyncLocalStorge.Value = new List <SEDbContextStorge>(); SEDbContext dbContext = new SEDbContext(dbContextConfig.Connection, dbContextConfig.EntityMapper, dbContextConfig.Type); SEDbContextStorge dbcontextStorge = new SEDbContextStorge(name, dbContext); _asyncLocalStorge.Value.Add(dbcontextStorge); return(dbContext); } else { var context = _asyncLocalStorge.Value.FirstOrDefault(f => f.Name == name).Context; if (context == null) { context = new SEDbContext(dbContextConfig.Connection, dbContextConfig.EntityMapper, dbContextConfig.Type); SEDbContextStorge dbcontextStorge = new SEDbContextStorge(name, context); _asyncLocalStorge.Value.Add(dbcontextStorge); } return(context); } }
public BaseRepository() { _dbContext = SEDbContextManager.GetDbContext(); }
public BaseRepository(string name) { _dbContext = SEDbContextManager.GetDbContext(name); }
public SEUnitOfWork() { _dbContext = SEDbContextManager.GetDbContext(); }
public SEUnitOfWork(string connectionName) { _dbContext = SEDbContextManager.GetDbContext(connectionName); }