【发布时间】:2015-08-07 05:04:22
【问题描述】:
我是 Unity 和 Identity 的新手,我已经重组了 Identity 2 的实现以使用 int 键而不是字符串。我关注了this article。在这一点上效果很好。但是,我正在使用 Unity for IoC,它与我的存储库完美配合,但是,我正在努力让它与 Identity 方面一起工作。我跟着this article 切换。
我见过与此类似的问题,但他们都使用字符串键,所以我认为我在使用 int 的地方有一些时髦的东西。
问题出在 ApplicationUserStore 类的 ctor 中:
public class ApplicationUserStore :
UserStore<ApplicationUser, ApplicationRole, int,
ApplicationUserLogin, ApplicationUserRole,
ApplicationUserClaim>, IUserStore<ApplicationUser, int>,
IDisposable
{
public ApplicationUserStore(IdentityDb context)
: base(context)
{
}
}
这里是IdentityDb.cs:
public class IdentityDb : IdentityDbContext<ApplicationUser, ApplicationRole, int,
ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{
public IdentityDb()
: base("DefaultConnection")
{
}
static IdentityDb()
{
// Set the database initializer which is run once during application start
// This seeds the database with admin user credentials and admin role
Database.SetInitializer<IdentityDb>(new IdentityDbInitializer());
}
public static IdentityDb Create()
{
return new IdentityDb();
}
}
这是UnityConfig.cs的相关部分:
container.RegisterType<IdentityDb>(new PerResolveLifetimeManager());
container.RegisterType<ApplicationSignInManager>();
container.RegisterType<ApplicationUserManager>();
container.RegisterType<ApplicationRoleManager>();
container.RegisterType<IAuthenticationManager>(
new InjectionFactory(c=>HttpContext.Current.GetOwinContext().Authentication));
container.RegisterType<IUserStore<ApplicationUser, int>, ApplicationUserStore>(
new InjectionConstructor(typeof(IdentityDb)));
当我尝试运行应用程序时,ApplicationUserStore 的 ctor 中的 context 参数是 null。
如果能提供任何帮助,我将不胜感激。
谢谢!
【问题讨论】:
标签: c# asp.net entity-framework unity-container asp.net-identity