Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom ActionInvoker vs custom FilterProvider for ActionFilter dependency injection in MVC 3

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?

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.

like image 919
Andrew Best Avatar asked Nov 20 '11 05:11

Andrew Best


1 Answers

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.

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.

like image 189
Remo Gloor Avatar answered Oct 03 '22 13:10

Remo Gloor