public DbContextFactory(IServiceProvider _serviceProvider, IEFOptionsFactory _eFOptionsFactory) { _masterDbContexts = new ConcurrentDictionary <Type, DbContext>(); _slaveDbContexts = new ConcurrentDictionary <Type, DbContext>(); serviceProvider = _serviceProvider; eFOptionsFactory = _eFOptionsFactory; }
public RepositoryInfrastructureBase(RepositoryOptions <TDbContext> _unitOfWorkOptions, IEFOptionsFactory eFOptionsFactory) { unitOfWorkOptions = _unitOfWorkOptions; options = eFOptionsFactory.Get <TDbContext>(); }
/// <summary> /// 构造注入 /// </summary> /// <param name="_options"></param> /// <param name="_service"></param> public BaseRepository(IServiceProvider _service, RepositoryOptions <TDbContext> _unitOfWorkOptions, IDbContextFactory _repositoryFactory, IRepositoryMediator <TDbContext> _repositoryMediator, IEFOptionsFactory eFOptionsFactory) { unitOfWorkOptions = _unitOfWorkOptions; //获取上下文类型 unitOfWorkOptions.DbContextType = typeof(TDbContext); //获取ef的配置信息 var dbInfo = eFOptionsFactory.Get <TDbContext>(); unitOfWorkOptions.WriteReadConnectionString = dbInfo?.WriteReadConnectionString; //是否开启读写分离操作 unitOfWorkOptions.IsOpenMasterSlave = dbInfo.IsOpenMasterSlave; //获取上下文 var _dbContext = _service.GetService(unitOfWorkOptions.DbContextType) as DbContext; //设置上下文工厂 _repositoryFactory.Set(unitOfWorkOptions?.DbContextType, _dbContext); repositoryMediator = _repositoryMediator; }