Beispiel #1
0
 public RepositoryReadInfrastructure(IDbContextFactory _factory, IRepositoryInfrastructureBase <TDbContext> _infrastructureBase, RepositoryOptions <TDbContext> _unitOfWorkOptions)
 {
     factory            = _factory;
     infrastructureBase = _infrastructureBase;
     unitOfWorkOptions  = _unitOfWorkOptions;
     //验证是否开启了事务 如果开启了事务 就获取主库的连接
     //或者没有开启读写分离 直接使用 主库的数据
     if (_unitOfWorkOptions.IsBeginTran || !_unitOfWorkOptions.IsOpenMasterSlave)
     {
         slaveDbContext = _factory.GetMaster <TDbContext>();
         IsMaster       = true;
     }
     else
     {
         slaveDbContext = _factory.GetSlave <TDbContext>();
         _infrastructureBase.SwitchSlaveAsync(slaveDbContext).ConfigureAwait(false).GetAwaiter().GetResult();
     }
 }