/// <summary> /// 取得服务实例,实例为单实例对象,释放实例只能用Reset()方法。 /// </summary> /// <param name="daoFilePath">dao文件路径, 如传入空则由AppSettings["DaoFile"]决定</param> /// <returns>服务实例</returns> public static ServiceConfig GetInstance(string daoFilePath) { if (_instance == null) { object synRoot = _synRoot; lock (synRoot) { if (_instance == null) { ConfigureHandler configureHandler = new ConfigureHandler(Reset); DomDaoManagerBuilder domDaoManagerBuilder = new DomDaoManagerBuilder(); string text = string.IsNullOrEmpty(daoFilePath) ? ConfigurationManager.Configuration.GetSection("serviceCore:daoFile").Value : daoFilePath; if (!Path.IsPathRooted(text)) { text = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, text); } if (!File.Exists(text)) { throw new Exception("AppSettings中指定的配置文件(DaoFile)不存在!"); } try { domDaoManagerBuilder.ConfigureAndWatch(text, configureHandler); } catch (Exception ex2) { Exception ex = ex2; while (ex.InnerException != null) { ex = ex.InnerException; } throw new Exception("dao.config不存在或错! " + ex2.Message, ex); } _instance = new ServiceConfig { DaoManager = IBatisNet.DataAccess.DaoManager.GetInstance("SqlMapDao") }; ModifyConnectString(_instance.DaoManager, "SqlMapDao"); } } } return(_instance); }
/// <summary> /// 释放实例现有实例。 /// </summary> /// <param name="obj"></param> public static void Reset(object obj) { _instance = null; }