예제 #1
0
        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);
            }
        }
예제 #2
0
 public BaseRepository()
 {
     _dbContext = SEDbContextManager.GetDbContext();
 }
예제 #3
0
 public BaseRepository(string name)
 {
     _dbContext = SEDbContextManager.GetDbContext(name);
 }
예제 #4
0
 public SEUnitOfWork()
 {
     _dbContext = SEDbContextManager.GetDbContext();
 }
예제 #5
0
 public SEUnitOfWork(string connectionName)
 {
     _dbContext = SEDbContextManager.GetDbContext(connectionName);
 }