Skip to content

Instantly share code, notes, and snippets.

@Bostonncity
Forked from 3nth/AutofacConfig
Created December 5, 2015 19:44
Show Gist options
  • Save Bostonncity/fa7e92bb808347bed88b to your computer and use it in GitHub Desktop.
Save Bostonncity/fa7e92bb808347bed88b to your computer and use it in GitHub Desktop.
AutofacConfig for ASP.NET Identity
public class AutofacConfig
{
public static void Configure()
{
var builder = new ContainerBuilder();
builder.RegisterType<ApplicationDbContext>().AsSelf().InstancePerLifetimeScope();
builder.RegisterType<ApplicationUserStore>().As<IUserStore<PortalUser>>().InstancePerLifetimeScope();
builder.RegisterType<ApplicationUserManager>().AsSelf().InstancePerLifetimeScope();
builder.RegisterType<ApplicationSignInManager>().AsSelf().InstancePerLifetimeScope();
builder.Register<IAuthenticationManager>(c => HttpContext.Current.GetOwinContext().Authentication);
builder.RegisterModule(new AutofacWebTypesModule());
builder.RegisterFilterProvider();
builder.RegisterControllers(Assembly.GetExecutingAssembly());
IContainer container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment