Bon*_*nyT 15 c# asp.net-mvc dependency-injection castle-windsor action-filter
在我的ASP.Net MVC应用程序中,我实现了一个Custom ActionFilter来授权用户.
我使用CastleWindsor为所有控制器提供依赖注入,如下所示:
protected virtual IWindsorContainer InitializeServiceLocator()
{
IWindsorContainer container = new WindsorContainer();
ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container));
container.RegisterControllers(typeof(HomeController).Assembly);
ComponentRegistrar.AddComponentsTo(container);
ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container));
return container;
}
Run Code Online (Sandbox Code Playgroud)
在我的CustomAttribute中,我需要一个由我的所有控制器使用的依赖项,但是我无法在属性中使用基于构造函数的注入.
那么这里最干净的方法是什么?我该如何提供依赖?
Bon*_*nyT 13
好的 - 这似乎是数据库注入到ASP MVC和Castle Windsor的验证属性的副本,已经得到了回答.
另外,我如何使用Windsor将依赖项注入ActionFilterAttributes.
仔细阅读以上内容和参考文章 - 对我来说关键的一点是http://weblogs.asp.net/psteele/archive/2009/11/04/using-windsor-to-inject-dependencies-into-asp -net-mvc-actionfilters.aspx对于任何有兴趣的人.
| 归档时间: |
|
| 查看次数: |
10262 次 |
| 最近记录: |