asp.net-mvc-2 – 如何使用Castle Windsor在MVC中注入UrlHelper
发布时间:2020-12-15 20:49:39 所属栏目:asp.Net 来源:网络整理
导读:我有一个依赖于UrlHelper的组件,我需要使用Castle Windsor注册. UrlHelper反过来又对RequestContext(和RouteCollection)有所了解. 现在我的控制器有一个类型为UrlHelper的Url属性,但据我所知,它无法真正访问它. 注册我的UrlHelper依赖项的最有效方法是什么(
我有一个依赖于UrlHelper的组件,我需要使用Castle Windsor注册. UrlHelper反过来又对RequestContext(和RouteCollection)有所了解.
现在我的控制器有一个类型为UrlHelper的Url属性,但据我所知,它无法真正访问它. 注册我的UrlHelper依赖项的最有效方法是什么(使用流畅的配置)? 解决方法
不漂亮,没有测试,但它应该工作:
container.AddFacility<FactorySupportFacility>(); container.Register(Component.For<UrlHelper>() .LifeStyle.PerWebRequest .UsingFactoryMethod(() => { var context = new HttpContextWrapper(HttpContext.Current); var routeData = RouteTable.Routes.GetRouteData(context); return new UrlHelper(new RequestContext(context,routeData)); })); Windsor的未来版本不需要FactorySupportFacility来使用UsingFactoryMethod. 无论如何,对UrlHelper依赖似乎很奇怪…… (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc-4 – DD4T默认路由不起作用
- 通过Knockout使用MVVM的asp.net MVC,将模型传递给j??avascr
- 一步一步学asp.net Ajax登录设计实现解析
- asp.net – Visual Studio 2015 RC中的界面上的错误“Visua
- asp.net-mvc – ASP.NET MVC.如何创建接受和multipart / fo
- asp.net – LinkBut??ton命令事件似乎没有被解雇
- 在ASP.Net中使用Page_Load和Page_PreRender
- asp.net-mvc – 为服务层设计DI(构造函数注入)的存储库
- asp.net mvc路由id参数
- Asp.Net(vb)在代码隐藏中强制回发