Autofac Activating MVC 4 Action Filter Properties

I am using the Nuget MVC3 integration package for Autofac with MVC4. It works mostly (embedding a constructor with controllers works fine), but it does not enter registered services into the properties of the action filter.

This is my registration at Global.asax.cs:

builder.RegisterType<AspNetMembershipProviderWrapper>().As(typeof(IUserService)).InstancePerHttpRequest();
// 5) action filters
builder.RegisterType<SetCultureAttribute>().As<IActionFilter>().PropertiesAutowired().SingleInstance();
builder.RegisterFilterProvider();
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

Then in SetCultureAttributeI have this:

public IUserService _userService { get; set; } // it doesn't get injected, null

And this does not work in the attribute constructor:

_userService = DependencyResolver.Current.GetService<AspNetMembershipProviderWrapper>(); // always returns null

DependencyResolver.Current.GetService() also returns null for all other registered services when called in the constructor of the action filter (I tried it in Debug windows to check it).

So, I think something is not working correctly. Is it possible to use MVC3 integration or use the Nuget MVC4 package (which says this for RC)?

Is there anything else that I could try to make this work?

+5
1

ActionFilter, , :

builder.RegisterFilterProvider();

: http://code.google.com/p/autofac/wiki/MvcIntegration3

IUserService, .

_userService = DependencyResolver.Current.GetService<IUserService>();

. wiki .

+9

All Articles