Dependency Injection Structuremap ASP.NET Identity MVC 5

前端 未结 3 1548
慢半拍i
慢半拍i 2020-12-29 08:07

I\'m using the new ASP.NET MVC 5 Identity framework for authentication. I\'ve traditionally used StructureMap for dependency injection, but I\'m having problems wiring it u

相关标签:
3条回答
  • 2020-12-29 08:31

    @vikram, this worked for me.

    cfg.For<IRoleStore<IdentityRole,string>>().Use<RoleStore<IdentityRole>>(); 
    
    0 讨论(0)
  • 2020-12-29 08:43

    Adding [DefaultConstructor] Attribute will work.

    public class AccountController : Controller
    {
        private ApplicationSignInManager _signInManager;
        private ApplicationUserManager _userManager;
    
        [DefaultConstructor]  //This is the attribute you need to add on the constructor
        public AccountController()
        {
        }
       // Other implementations here..........
    }
    
    0 讨论(0)
  • 2020-12-29 08:47

    Add following code to your Container initialize method.

    x.For<Microsoft.AspNet.Identity.IUserStore<ApplicationUser>>()
    .Use<Microsoft.AspNet.Identity.EntityFramework.UserStore<ApplicationUser>>();
    
    x.For<System.Data.Entity.DbContext>().Use(() => new ApplicationDbContext());
    
    0 讨论(0)
提交回复
热议问题