using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Configuration; using System.Reflection; namespace Common.DALFactory { /// <summary> /// 数据层对象实例创建 /// </summary> public partial class DbFactory { /// <summary> /// 做缓存 /// </summary> private static Dictionary<string, object> dic = new Dictionary<string, object>(); #region 程序集配置 -static readonly string DALAssembly /// <summary> /// 程序集配置 /// </summary> private static readonly string DALAssembly = ConfigurationManager.AppSettings["dalAssembly"]; #endregion #region 命名空间配置 -static readonly string DALNameSpace /// <summary> /// 命名空间配置 /// </summary> private static readonly string DALNameSpace = ConfigurationManager.AppSettings["dalNameSpace"]; #endregion #region 创建对象实例 -static object CreateInstance(string fullName, string assemblyName) /// <summary> /// 创建对象实例 /// </summary> /// <param name="fullName">全名称 命名空间.类名</param> /// <param name="assemblyName">程序集名称</param> /// <returns></returns> private static object CreateInstance(string fullName, string assemblyName) { string key = string.Format("{0}+{1}", assemblyName, fullName); if (!dic.ContainsKey(key)) { Assembly assembly = Assembly.Load(assemblyName); // 加载程序集 object obj = assembly.CreateInstance(fullName); dic.Add(key, obj); } return dic[key]; } #endregion } }