How do you wire up a ASP.NET MVC 5 UserManager instance with Autofac?

asp.net-mvc, asp.net-mvc-5, autofac, dependency-injection

Solution

I don't know AutoFac, but wild guess:

builder.RegisterType<ApplicationUserStore<ApplicationUser>>()
    .As<IUserStore<ApplicationUser>>();
builder.RegisterType<UserManager<ApplicationUser>>();

Problem

With the MVC 5 release comes the Asp.Net.Identity bits including the UserManager. Instantiation can get messy and I'm trying to add with Autofac controller settings. Controller's constructor ``` public LoginController(UserManager<ApplicationUser> userManager) { UserManager = userManager; } ``` Manually creating a new instance: ``` var controller = new LoginController(UserManager<ApplicationUser>(new ApplicationUserStore<ApplicationUser>(new MyDbContext()))); ``` ApplicationUserStore class/constructor: ``` public class ApplicationUserStore<TUser> : IUserLoginStore<TUser>, IUserStore<TUser>, IDisposable where TUser : ApplicationUser public ApplicationUserStore(IMyDbContext context) { Context = context; } ``` I have new for the db context working correctly: ``` builder.RegisterType<MyDbContext>().As<IMyDbContext>(); ``` What would be the registration signature for the LoginController?

Original source