2014-11-03 64 views
2

我有問題要註冊一些這樣的依賴關係。Structuremap x Asp.net Identity

No default Instance is registered and cannot be automatically determined for type 'IUserStore<ApplicationIdentityUser, Int32>' 

There is no configuration specified for IUserStore<ApplicationIdentityUser, Int32> 


1.) new UserManager`2(*Default of IUserStore<ApplicationIdentityUser, Int32>*) 
2.) UserManager<ApplicationIdentityUser, Int32> 
3.) Instance of UserManager<ApplicationIdentityUser, Int32> 
4.) new ApplicationUserManager(*Default of UserManager<ApplicationIdentityUser, Int32>*, *Default of IAuthenticationManager*) 
5.) MyClinic.Infra.Data.Identity.ApplicationUserManager 
6.) Instance of MyClinic.Core.Identity.IApplicationUserManager (MyClinic.Infra.Data.Identity.ApplicationUserManager) 
7.) new AccountController(*Default of IApplicationUserManager*) 
8.) MyClinic.Web.Controllers.AccountController 
9.) Instance of MyClinic.Web.Controllers.AccountController 
10.) Container.GetInstance(MyClinic.Web.Controllers.AccountController) 

有人可以幫我嗎?

我的帳戶控制器:

public class AccountController : Controller 
{ 
    private IApplicationUserManager _userManager; 
    public AccountController(IApplicationUserManager userManager) 
    { 
     _userManager = userManager; 
    } 
} 

我的應用程序用戶管理:

public class ApplicationUserManager : IApplicationUserManager 
{ 
    private readonly UserManager<ApplicationIdentityUser, int> _userManager; 
    private readonly IAuthenticationManager _authenticationManager; 
    private bool _disposed; 

    public ApplicationUserManager(UserManager<ApplicationIdentityUser, int> userManager, IAuthenticationManager authenticationManager) 
    { 
     _userManager = userManager; 
     _authenticationManager = authenticationManager; 
    } 
} 
+0

有此問題的其他變化。 這可能會幫助你:http://stackoverflow.com/a/27244289/351204 – 2014-12-03 09:20:48

回答

15

您需要添加以下到您的structuremap容器與Asp.net身份工作。

For<IUserStore<ApplicationUser>>().Use<UserStore<ApplicationUser>>(); 
For<DbContext>().Use(() => new ApplicationDbContext()); 
For<IAuthenticationManager>().Use(() => HttpContext.Current.GetOwinContext().Authentication); 

此外,您將需要安裝包

Microsoft.Owin.Host.SystemWeb 

得到擴展方法GetOwinContext()出現在HttpContext.Current

+0

謝謝,它幫助。 – SHM 2015-08-17 09:41:00