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