asp.net-mvc-2 – 如何使用Castle Windsor在MVC中注入UrlHelper
发布时间:2020-09-21 14:17:37 所属栏目: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 – 允许asp.net mvc 2控制器名称的URL中的连字
- asp.net-mvc – 如何在ASP.NET MVC中生成弹出页面链接
- asp.net-core – 如何使用FluentValidation.AspNetCore和Fl
- asp.net-mvc-4 – MVC4捆绑GZIP和头文件
- asp.net-mvc – 命名约定 – 控制器的一个规则,没有模型和视
- asp.net – 将ViewState移出页面?
- asp.net – 我可以愚弄HttpRequest.Current.Request.IsLoca
- asp.net-web-api – WebApi 2.1 PUT抛出错误415
- asp.net-mvc-4 – MVC4 RC脚本捆绑很慢
- asp.net – 我可以在超链接上显式指定NavigateUrl吗?
