Action Filter not firing

Feb 19, 2012 at 11:56 PM

After installing SimpleInjector.Mvc nuget package, Action Filter like [Authorize] no longer fires. If I comment out the below line, action filter starts working.


Is there any side effect of commenting out this line?
Feb 20, 2012 at 5:12 AM
Edited Jan 16, 2014 at 7:55 AM
Hi, I incorrectly assumed that MVC would request an IFilterProvider from the dependency resolver, but it seems to get it directly from the static FilterProviders class. The RegisterAttributeFilterProvider method of the MVC NuGet package should have registered the SimpleInjectorFilterAttributeFilterProvider to the FilterProviders class. What you can do to fix this is, go to the definition of the RegisterAttributeFilterProvider method and replace the following line:
container.RegisterSingle<IFilterProvider, SimpleInjectorFilterAttributeFilterProvider>(); 
with the following:
FilterProviders.Providers.Add(new SimpleInjectorFilterAttributeFilterProvider(container));
I hope this helps.
Feb 20, 2012 at 6:07 AM


It is working now.

Feb 26, 2012 at 7:16 PM

A new version of the SimpleInjector.MVC3 NuGet package has been uploaded to NuGet. This package contains the fix and a few other minor changes. Please note that updating this package from the previous version will have no effect, since the NuGet package manager will not override an existing content file. If you are updating form a previous version of the SimpleInjector.MVC3 package, you will have to install it in a empty project and copy the SimpleInjectorMVC3Extensions.cs from the empty project to your real project.

Jul 1, 2012 at 11:44 PM

I've got this exact problem. I'm using v1.4.2.12141 and this fix doesn't appear to be in the source.

I've even made the change here and it still doesn't fix it.

Any other ideas?

many thanks

Jul 2, 2012 at 12:09 AM

Ah, I think I have it. I needed to add that line at the end otherwise the filter provider gets remove;

public static void RegisterMvcAttributeFilterProvider(this Container container)      
            if (container == null)
                throw new ArgumentNullException("container");

            var singletonFilterProvider = new SimpleInjectorFilterAttributeFilterProvider(container);

            var providers = FilterProviders.Providers.OfType<FilterAttributeFilterProvider>().ToList();

            providers.ForEach(provider => FilterProviders.Providers.Remove(provider));

            FilterProviders.Providers.Add(new SimpleInjectorFilterAttributeFilterProvider(container));

Jul 3, 2012 at 2:11 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Jul 3, 2012 at 9:08 PM

I just published a new version of the MVC3 Integration NuGet package that fixes this bug.

Marked as answer by dot_NET_Junkie on 11/4/2013 at 1:56 AM