I am new to Unity, and Identity, and I have restructured my implementation of Identity 2 to use int Keys instead of strings. I followed this article. It works great at this point. However, I am using Unity for IoC, and it works wonderfully with my repositories, however, I am struggling getting it to work with the Identity side. I followed this article to switch.
I have seen questions similar to this, but all of them were using string Keys, so I assume I have something funky somewhere since I am using int.
The issue is in the ctor of the ApplicationUserStore
class:
public class ApplicationUserStore :
UserStore<ApplicationUser, ApplicationRole, int,
ApplicationUserLogin, ApplicationUserRole,
ApplicationUserClaim>, IUserStore<ApplicationUser, int>,
IDisposable
{
public ApplicationUserStore(IdentityDb context)
: base(context)
{
}
}
Here is the 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();
}
}
And here is the relevant portion of 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)));
When I attempt to run the app, the context
parameter in the ctor of ApplicationUserStore
is null
.
I would appreciate any help that could be offered.
Thank you!