依赖注入研究
依赖注入研究:
View Code
public class BaseBusiness { protected ITSysOperationLogDal buLog; public BaseBusiness(ITSysOperationLogDal log) { this.buLog = log; } /// <summary> /// 返回T类型的实体,T需要继承BaseBusiness /// 默认container节点名称为业务类名称 /// </summary> /// <typeparam name="T">返回值类型</typeparam> /// <returns></returns> public static T Create<T>() where T : BaseBusiness { IUnityContainer container = new UnityContainer(); UnityConfigurationSection section = (UnityConfigurationSection)System.Configuration.ConfigurationManager.GetSection("unity"); section.Configure(container, typeof(T).Name); T tModel = (T)container.Resolve<BaseBusiness>(); return tModel; } /// <summary> /// 返回T类型的实体,T需要继承BaseBusiness /// </summary> /// <typeparam name="T">返回值类型</typeparam> /// <param name="containerName">需要实例化的container节点名称</param> /// <returns></returns> public static T Create<T>(string containerName) where T : BaseBusiness { IUnityContainer container = new UnityContainer(); UnityConfigurationSection section = (UnityConfigurationSection)System.Configuration.ConfigurationManager.GetSection("unity"); section.Configure(container, containerName); T tModel = (T)container.Resolve<BaseBusiness>(); return tModel; } /// <summary> /// 保存日志,用户信息从Cookie获取 /// </summary> /// <param name="opType">操作类型</param> /// <param name="remark">备注信息</param> protected void LogSave(OperationType opType,string remark) { System.Web.HttpCookie userInfo = System.Web.HttpContext.Current.Request.Cookies["UserInfo"] ?? null; if (userInfo == null) { SysLog.Debug("DebugLog", "用户还未登录,无法获取相关Cookie"); } TSysOperationLog logModel = new TSysOperationLog() { OperationType = (short)opType, OperationUserID = new Guid(userInfo["UserID"]), OperationUserName = userInfo["UserName"].ToString(), UserDomainID = new Guid(userInfo["DomainID"]), OperationTime = DateTime.Now, Remark = remark }; ExHandler.Execute<bool,TSysOperationLog>(buLog.Add, logModel); } /// <summary> /// 保存日志,用户信息需要传入 /// </summary> /// <param name="opType">操作类型</param> /// <param name="userID">用户ID</param> /// <param name="userName">用户名</param> /// <param name="userDomainID">用户所属域</param> /// <param name="remark">备注信息</param> protected void LogSave(OperationType opType,Guid userID, string userName, Guid userDomainID , string remark) { TSysOperationLog logModel = new TSysOperationLog() { OperationType = (short)opType, OperationUserID = userID, OperationUserName = userName, UserDomainID = userDomainID, OperationTime = DateTime.Now, Remark = remark }; ExHandler.Execute<bool, TSysOperationLog>(buLog.Add, logModel); } }
阿里云: www.aliyun.com
华赐软件: www.huacisoft.com
C#开源社区: www.opencsharp.net
清泓美肤苑: 清泓美肤苑
bootstrap权限管理系统: Asp.Net Mvc3 bootstrap权限管理系统