Ejemplo n.º 1
0
        /// <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;
        }
Ejemplo n.º 2
0
 public RepositoryInfrastructureBase(RepositoryOptions <TDbContext> _unitOfWorkOptions, IEFOptionsFactory eFOptionsFactory)
 {
     unitOfWorkOptions = _unitOfWorkOptions;
     options           = eFOptionsFactory.Get <TDbContext>();
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 获取efoption
 /// </summary>
 /// <param name="DbContextType"></param>
 /// <returns></returns>
 private EFOptions GetEfOption(Type DbContextType)
 {
     return(eFOptionsFactory.Get(DbContextType));
 }