自ActionInvoker VS在MVC 3 ActionFilter依赖注入定制FilterProvider [英] Custom ActionInvoker vs custom FilterProvider for ActionFilter dependency injection in MVC 3

查看:263
本文介绍了自ActionInvoker VS在MVC 3 ActionFilter依赖注入定制FilterProvider的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以摆脱上的优势,并使用自定义ActionInvoker <一个缺点一些轻href=\"http://$c$cclimber.net.nz/archive/2009/02/10/how-to-use-ninject-to-inject-dependencies-into-asp.net-mvc.aspx\">like所以来定制ActionFilters执行依赖注入,而不是使用自定义FilterProvider 因为这里证明?

Can anyone shed some light on the advantages and disadvantages of using a custom ActionInvoker like so to perform dependency injection on custom ActionFilters as opposed to using a custom FilterProvider as demonstrated here?

在这两种情况下,你要还是要避免在您的ActionFilters构造函数注入,而对我来说,似乎所有的定制FilterProvider确实在这种情况下增加其注册您的ActionFilters的额外开销,并在你的容器提供者

In both cases you are going to still want to avoid constructor injection on your ActionFilters, and to me it seems that all the custom FilterProvider does in this case is adds additional overhead of having to register your ActionFilters and the provider in your container.

推荐答案

过滤器供应商的一大优点是,它允许构造函数注入,如果做得正确。您链接的例子并不正确证明这一点。使用构造器注入不能使用过滤器的属性。相反,你必须将两件事情,你要应用的过滤器(例如,使用一个属性)的申报和过滤器实现分离。

The big advantage of filter providers is that it allows constructor injection if done right. The example you linked does not demonstrate this correctly. To use constructor injection you can not use filter attributes. Instead you have to separate the two things the declaration that you want to apply a filter (e.g. using an attribute) and the filter implementation.

我不知道是否有团结一个良好的实施。查看的http://www.planetgeek.ch/2010/11/13/official-ninject-mvc-extension-gets-support-for-mvc3/怎么可能感觉。但是,这是一个Ninject例子。也许你可以把它在github和端口执行其统一。

I'm not sure if there is a good implementation for Unity. See on http://www.planetgeek.ch/2010/11/13/official-ninject-mvc-extension-gets-support-for-mvc3/ how it could feel like. But this is a Ninject example. Probably you can take its implementation on github and port it to Unity.

这篇关于自ActionInvoker VS在MVC 3 ActionFilter依赖注入定制FilterProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆