How to plug my Autofac container into ASP. NET Identity 2.1

后端 未结 5 1235
攒了一身酷
攒了一身酷 2020-12-12 15:29

I have been looking into the new features of the new version of ASP.NET Identity 2.1 and one of its enhancements is the new IoC features integrated into the OWIN Middleware.

5条回答
  •  长情又很酷
    2020-12-12 15:53

    For reference here's how you can wire everything up using Unity:

    var container = new UnityContainer();
    
    container.RegisterType(new InjectionConstructor("ConnectionStringName"));
    
    container.RegisterType(
       new InjectionFactory(c => HttpContext.Current.GetOwinContext().Authentication));
    
    container.RegisterType, UserStore>(
       new InjectionConstructor(typeof(MyDbContext)));
    
    container.RegisterType, RoleStore>(
       new InjectionConstructor(typeof(MyDbContext)));
    
    container.RegisterType>(new InjectionFactory(x =>
       new IdentityFactoryOptions
       {
          DataProtectionProvider = new Microsoft.Owin.Security.DataProtection.DpapiDataProtectionProvider("ApplicationName")
       }));
    
    container.RegisterType();
    
    DependencyResolver.SetResolver(new UnityDependencyResolver(container));
    

提交回复
热议问题