Custom ActionInvoker vs custom FilterProvider filter for injecting ActionFilter dependencies in MVC 3

Can someone shed light on the advantages and disadvantages of using custom ActionInvoker in such a way as to inject dependencies on custom ActionFilters, rather than using a custom FilterProvider as shown here ?

In both cases, you still want to avoid constructor injection in your ActionFilters, and for me it seems that all the custom FilterProvider in this case add extra overhead to registering your ActionFilters and the provider in your container.

+7
dependency-injection asp.net-mvc-3 unity-container
source share
1 answer

A great advantage of filter suppliers is that it allows you to inject the designer if this is done correctly. The example you provided does not show this correctly. To use constructor injection, you cannot use filter attributes. Instead, you need to separate two things from the declaration that you want to apply to the filter (for example, using an attribute) and the filter implementation.

I'm not sure if there is a good implementation for Unity. See http://www.planetgeek.ch/2010/11/13/official-ninject-mvc-extension-gets-support-for-mvc3/ for what it might seem. But this is an example of Ninject. You can probably implement it on github and port it to Unity.

+4
source share

All Articles