1、接口适配层:
方式一:动态调用RPC数据服务
方式二:基于策略模式,动态加载dll实现,例如
/// <summary> /// 获得广告位置列表 /// </summary> /// <param name="pageSize">每页数</param> /// <param name="pageNumber">当前页数</param> /// <returns></returns> IDataReader GetAdvertPositionList(int pageSize, int pageNumber); static BMAData() { try { string[] fileNameList = Directory.GetFiles(System.Web.HttpRuntime.BinDirectory, "TMall.RDBSStrategy.*.dll", SearchOption.TopDirectoryOnly); _irdbsstrategy = (IRDBSStrategy)Activator.CreateInstance(Type.GetType(string.Format("TMall.RDBSStrategy.{0}.RDBSStrategy, TMall.RDBSStrategy.{0}", fileNameList[0].Substring(fileNameList[0].LastIndexOf("RDBSStrategy.") + 13).Replace(".dll", "")), false, true)); } catch { throw new BMAException("创建'关系数据库策略对象'失败,可能存在的原因:未将'关系数据库策略程序集'添加到bin目录中;'关系数据库策略程序集'文件名不符合'TMall.RDBSStrategy.{策略名称}.dll'格式"); } _enablednosql = Directory.GetFiles(System.Web.HttpRuntime.BinDirectory, "TMall.NOSQLStrategy.*.dll", SearchOption.TopDirectoryOnly).Length > 0; } /// <summary> /// 关系型数据库 /// </summary> public static IRDBSStrategy RDBS { get { return _irdbsstrategy; } } /// <summary> /// 用户非关系型数据库 /// </summary> public static IUserNOSQLStrategy UserNOSQL { get { if (_enablednosql && BMAConfig.RedisNOSQLConfig.User.Enabled == 1) { if (_iusernosqlstrategy == null) { lock (_locker) { if (_iusernosqlstrategy == null) { try { string[] fileNameList = Directory.GetFiles(System.Web.HttpRuntime.BinDirectory, "TMall.NOSQLStrategy.*.dll", SearchOption.TopDirectoryOnly); _iusernosqlstrategy = (IUserNOSQLStrategy)Activator.CreateInstance(Type.GetType(string.Format("TMall.NOSQLStrategy.{0}.UserNOSQLStrategy, TMall.NOSQLStrategy.{0}", fileNameList[0].Substring(fileNameList[0].LastIndexOf("NOSQLStrategy.") + 14).Replace(".dll", "")), false, true)); } catch { throw new BMAException("创建'用户非关系数据库策略对象'失败,可能存在的原因:未将'用户非关系数据库策略程序集'添加到bin目录中;'用户非关系数据库策略程序集'文件名不符合'TMall.NOSQLStrategy.{策略名称}.dll'格式"); } } } } } return _iusernosqlstrategy; } }
标签:服务,TMall,RDBSStrategy,fileNameList,关系数据库,dll,分层,NOSQLStrategy,架构 From: https://www.cnblogs.com/binfirechen/p/16640554.html