Esempio n. 1
0
        /// <summary>
        /// 定义仓储,带参
        /// </summary>
        /// <param name="dbType">数据库类型</param>
        /// <returns></returns>
        protected IDatabase BaseRepository(DatabaseType dbType)
        {
            IDatabase database = null;

            this.Logger(this.GetType(), "定义仓储,带参-BaseRepository", () =>
            {
                UnityIocHelper helper = UnityIocHelper.UnityIocInstance;
                //特别注意:此处的 connStringName 参数名称必须与IDatabase实现类的构造函数参数名称一致
                ResolverOverride parm = UnityIocHelper.GetParameterOverride(BaseParameterName, BaseConnStringName);

                DbHandlingCenter.DbType = dbType;

                database = helper.GetService <IDatabase>(parm);
            }, e =>
            {
            });
            return(database);
        }
Esempio n. 2
0
        /// <summary>
        /// 定义仓储,带参
        /// </summary>
        /// <param name="connStringName">连接字符串配置项名称</param>
        /// <returns></returns>
        protected IDatabase BaseRepository(string connStringName)
        {
            IDatabase database = null;

            this.Logger(this.GetType(), "定义仓储,带参-BaseRepository", () =>
            {
                UnityIocHelper helper = UnityIocHelper.UnityIocInstance;
                //特别注意:此处的 connStringName 参数名称必须与IDatabase实现类的构造函数参数名称一致
                ResolverOverride parm = UnityIocHelper.GetParameterOverride(BaseParameterName, connStringName);

                string mapToName        = UnityIocHelper.GetmapToByName("DbContainer", "DatabaseType");
                DatabaseType dbType     = (DatabaseType)Enum.Parse(typeof(DatabaseType), mapToName, true);
                DbHandlingCenter.DbType = dbType;

                database = helper.GetService <IDatabase>(parm);
            }, e =>
            {
            });
            return(database);
        }
Esempio n. 3
0
        /// <summary>
        /// 连接数据库
        /// </summary>
        /// <param name="dbType">数据库类型</param>
        /// <param name="connConfigName">连接字符串配置项名称</param>
        /// <returns></returns>
        public IDatabase GetDatabase(DatabaseType dbType, string connConfigName)
        {
            string    cacheKey = string.Format("{0}:{1}", this.GetType().Name, string.Format("{0}_{1}_{2}", connConfigName, BaseParameterName, dbType.ToString()).GetMd5Code());
            IDatabase database = CallContext.GetData(cacheKey) as IDatabase;

            this.Logger(typeof(DbFactory), "连接数据库,带参-GetDatabase", () =>
            {
                if (database == null)
                {
                    UnityIocHelper helper = UnityIocHelper.UnityIocInstance;
                    //特别注意:此处的 connConfigName 参数名称必须与IDatabase实现类的构造函数参数名称一致
                    ResolverOverride parm = UnityIocHelper.GetParameterOverride(BaseParameterName, connConfigName);

                    DbTypeContainer.DbType = dbType;

                    database = helper.GetService <IDatabase>(parm);
                }
            }, e =>
            {
            });
            return(database);
        }