【转】Asp.net MVC 通过自定义ControllerFactory实现构造器注入(重写DefaultControllerFactory)
【转】Asp.net MVC 通过自定义ControllerFactory实现构造器注入
一、重写ControllerFactory的GetControllerInstance
ControllerFactory是asp.net中用于在运行时构造Controller的工厂 ,默认使用的工厂在构造Controller时,默认调用Controller的无参构造函数,所以要实现构造器注入,需要重写工厂中构造Controller的方法GetControllerInstance:
public class CustomControllerFactory : DefaultControllerFactory
{
protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext,Type controllerType)
{
//获取构造函数对象
var constructor = controllerType.GetConstructors()[];
//获取构造函数参数
var param = constructor.GetParameters();
//获取构造函数所需的参数
var paramNames = param.Select(a => {
var serviceType = (ServiceAttribute)(a.ParameterType.GetCustomAttributes(typeof(ServiceAttribute), true)[]);
var t = Type.GetType(serviceType.ServiceName + ", " + serviceType.ServiceNameSpace, true);
return Activator.CreateInstance(t);
}).ToArray();
IController controller = Activator.CreateInstance(controllerType, paramNames) as Controller;
return controller;
}
}
在获取构造函数参数的时候,需要让发射机制寻找到服务的程序集,所以在这个地方我定义了一个名为Service的特性:
public class ServiceAttribute : Attribute
{
private string _serviceName;
private string _serviceNamespace;
public ServiceAttribute(string serviceName, string serviceNamespace)
{
_serviceName = serviceName;
_serviceNamespace = serviceNamespace;
} public string ServiceName
{
get { return _serviceName; }
} public string ServiceNameSpace
{
get { return _serviceNamespace; }
}
}
二、定义服务接口:
[Service(serviceName: "InjectController.Service.Impl.AddService", serviceNamespace: "InjectController.Service.Impl")]
public interface IAddService
{
int Add(int a, int b);
}
serviceName是服务的全称,serviceNamespace是服务的命名空间。
三、继承服务接口并实现:
public class AddService:IAddService
{
public int Add(int a, int b)
{
return a + b;
}
}
四、在Controller中定义构造函数,引用服务接口
public class HomeController : Controller
{
private ILoggerService _loggerService;
private IAddService _addService;
public HomeController(ILoggerService loggerService,IAddService addService)
{
_loggerService = loggerService;
_addService = addService;
} public ActionResult Index(int num1, int num2)
{
_loggerService.Logger(num1.ToString() + "+" + num2.ToString() + "=" + _addService.Add(num1,num2).ToString() + " " + "\r\n");
return View("Index", new LoggerDTO() { LoggerContent = _loggerService.GetLogger() });
}
}
ILoggerService没有在文章中列出,其格式与IAddService相同。
五、在Global.asax中重新注册控制器工厂,覆盖默认的构造器工厂:
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles); RegisterCustomControllerFactory();
} private void RegisterCustomControllerFactory()
{
IControllerFactory factory = new CustomControllerFactory();
ControllerBuilder.Current.SetControllerFactory(factory);
}
}
运行:发现接口成功的在构造函数中被注入
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA2sAAAEFCAIAAADytujEAAAgAElEQVR4nO3dX4wl1YHf8X7qrKxez7ZXHWUbu2aEHf5Im00e7A2Y3XgGDZg/e8EBx7aMJYjYNg87yF6kWixLYdcybdAkaJ3VDhJwYwW3WJCx9g+GBCbrYnayJihonfBAkFA3Jc9gIsGu1s5DlLfKQ1Xde/7XOfXv3nv6+9F9mLmn6tS59afrd8+pqruWAAAAACHWFt0AAAAArJjlSpCPPfbYaHMBAACgnVVKkI/JHHM9ZjdIuwEAAA6ToRJki8RWTuw5S2OC9JwSAAAAoQZJkC1CW+gsJEgAAIBFGXwUOygO6v9QJmMUGwAAYOEWnCAdWVAPfLaq6IMEAAAY04AJskWfX2Pc9HyfBAkAADCcpRjF9pyYUWwAAIBlsEoJ0jYlfZAAAABjWpZ7sUMnJkECAAAsyhI9DzIhQQIAAKyCVfpNmsQSTH1u2eY6SAAAgL4sV4IEAADA8iNBAgAAIAwJEgAAAGFIkAAAAAhDggQAAEAYEiQAAADCLF2C3MqKtSLbspanG0WxVr82Usc0+eZkqEa2ahWW2dZGsbZWv7Qt6C5FX9gKALAyVi5B1tJsmRLkbMmOVo1sa6NYW5NX5PZ0fa3Ya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BAkAAIAwJEgAAACEIUECAAAgDAkSAAAAYUiQAAAACEOCBAAAQBgSJAAAAMKQIAEAABCGBAkAAIAwJEgAAACEIUECAAAgDAkSAAAAYUiQAAAACEOCBAAAQBgSJAAAAMKQIAEAABDm/wO3MsrrITifOQAAAABJRU5ErkJggg==" alt="" />
【转】Asp.net MVC 通过自定义ControllerFactory实现构造器注入(重写DefaultControllerFactory)的更多相关文章
- Asp.net MVC 通过自定义ControllerFactory实现构造器注入
一.重写ControllerFactory的GetControllerInstance ControllerFactory是asp.net中用于在运行时构造Controller的工厂 ,默认使用的工厂 ...
- 转:【译】Asp.net MVC 利用自定义RouteHandler来防止图片盗链
[译]Asp.net MVC 利用自定义RouteHandler来防止图片盗链 你曾经注意过在你服务器请求日志中多了很多对图片资源的请求吗?这可能是有人在他们的网站中盗链了你的图片所致,这会占用你 ...
- ASP.NET MVC中使用Unity进行依赖注入的三种方式
在ASP.NET MVC中使用Unity进行依赖注入的三种方式 2013-12-15 21:07 by 小白哥哥, 146 阅读, 0 评论, 收藏, 编辑 在ASP.NET MVC4中,为了在解开C ...
- Asp.net MVC 中使用 Ninject 实现依赖注入
松耦合.针对抽象编程.不针对实现编程是面向对象设计的原则.依赖注入就是,在一个类的内部,不通过创建对象的实例而能够获得实现了某个公开接口的对象引用.所谓的控制反转也是相同的意思.把依赖的创建转移到了使 ...
- asp.net mvc 中 一种简单的 URL 重写
asp.net mvc 中 一种简单的 URL 重写 Intro 在项目中想增加一个公告的功能,但是又不想直接用默认带的那种路由,感觉好low逼,想弄成那种伪静态化的路由 (别问我为什么不直接静态化, ...
- ASP.NET MVC学习笔记-----ControllerFactory
上面这张图是asp.net mvc的工作流程图,我们可以看到当一个http请求来临时,首先需要经过路由系统,路由系统从中获取一些路由信息,然后ControllerFactory根据所得到的路由信息生成 ...
- [ASP.NET MVC] 利用自定义的AuthenticationFilter实现Basic认证
很多情况下目标Action方法都要求在一个安全上下文中被执行,这里所谓的安全上下文主要指的是当前请求者是一个经过授权的用户.授权的本质就是让用户在他许可的权限范围内做他能够做的事情,授权的前提是请求者 ...
- asp.net MVC之 自定义过滤器(Filter) - shuaixf
一.系统过滤器使用说明 1.OutputCache过滤器 OutputCache过滤器用于缓存你查询结果,这样可以提高用户体验,也可以减少查询次数.它有以下属性: Duration :缓存的时间, 以 ...
- ASP.NET MVC 的自定义模型属性别名绑定
最近在研究 ASP.NET MVC 模型绑定,发现 DefaultModelBinder 有一个弊端,就是无法实现对浏览器请求参数的自定义,最初的想法是想为实体模型的属性设置特性(Attribute) ...
随机推荐
- ListView数据更新后,自动滚动到底部(聊天时常用)| Listview Scroll to the end of the list after updating the list
转:http://www.cnblogs.com/bjshsqlt/p/3311830.html If you would like to after you have updated by list ...
- [转]hive中自定义函数(UDAF)实现多行字符串拼接为一行
函数如何使用: hive> desc concat_test;OKa intb string hive> select * from concat_test;OK1 ...
- django —— Celery实现异步和定时任务
1. 环境 python==2.7 djang==1.11.2 # 1.8, 1.9, 1.10应该都没问题 celery-with-redis==3.0 # 需要用到redis作为中间人服务(Bro ...
- AIX上打包排除某些文件/文件夹
Syntax X/Open Standards: tar {-c|-r|-t|-u|-x} [-B] [ -d ] [ -E ] [ -F ] [-h ] [ -i ] [ -l ] [ -m ] [ ...
- Python给我的小伙伴来个微信机器人
[本文出自天外归云的博客园] 安装wxpy 首先你得去图灵机器人官网上注册个账号,登录后在机器人设置里面会有一个api_key,下文会用到! 然后说开发环境,我用的是python3环境,事先需要安装一 ...
- hdu1599(无向图的最小环模板)
题意:杭州有N个景区,景区之间有一些双向的路来连接,现在8600想找一条旅游路线,这个路线从A点出发并且最后回到A点,假设经过的路线为V1,V2,....VK,V1,那么必须满足K>2,就是说至 ...
- iOSUIPickerView使用
#import <UIKit/UIKit.h> @interface ViewController : UIViewController<UIPickerViewDelegate,U ...
- 基于jQuery仿QQ音乐播放器网页版代码
基于jQuery仿QQ音乐播放器网页版代码是一款黑色样式风格的网页QQ音乐播放器样式代码.效果图如下: 在线预览 源码下载 实现的代码. html代码: <div class="m ...
- 基于HTML5手机上下滑动翻页特效
基于HTML5手机上下滑动翻页特效.这是一款手机移动端触屏滑动翻页代码下载.效果图如下: 在线预览 源码下载 实现的代码. html代码: <section class="u-al ...
- idea中git git pull push需要反复输入密码
在使用idea开发的过程中,在终端terminal中git pull和git push时遇到一个问题,一个是 每次提交都需要输入用户名和密码,,从网上找了下解决方案,记录一下. 解决: 打开git终端 ...