Reputation: 47375
I see that by default, an MVC4 WebApi project has 2 IFilterProviders
: The ConfigurationFilterProvider
, and the ActionDescriptorFilterProvider
. When setting up a custom IFilterProvider
to do property depenency injection, is it appropriate to remove both of these from the Filters collection first? Or is it more appropriate to just remove the ActionDescriptorFilterProvider
, and leave the ConfigurationFilterProvider
in the collection?
Secondly, I see that after a WebApi Http ActionFilterAttribute
is constructed for a particular action, it seems to stay around. For example when I put a custom action filter on an ApiController Get method, it is only constructed the first time that method is called. Subsequent calls to the api method seem to reuse the same filter (constructor breakpoints are only hit during the first invocation). Is this right? Why is it different than an MVC actionfilter, where a new instance is created for each method invocation?
Upvotes: 3
Views: 1630
Reputation: 6618
is it appropriate to remove both of these from the Filters collection first?
I have been successful in implementing dependency injection on Action Filters without removing either of these FilterProviders. Infact, I am extending the ActionDescriptorFilterProvider
in my example using StructureMap.
http://evolutionarydeveloper.blogspot.co.uk/2012/11/webapi-actionfilter-dependency.html
I cannot shed any light on your second question I'm afraid :-)
Upvotes: 1