I have several scenarios where it is difficult for me to match types.
Scenario 1:
public AccountController()
: this(new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())))
{
}
public AccountController(UserManager<ApplicationUser> userManager)
{
UserManager = userManager;
}
Type definition
public class ApplicationUser : IdentityUser
{
}
public class UserStore<TUser> : IUserLoginStore<TUser>, IUserClaimStore<TUser>, IUserRoleStore<TUser>, IUserPasswordStore<TUser>, IUserSecurityStampStore<TUser>, IUserStore<TUser>, IDisposable where TUser : global::Microsoft.AspNet.Identity.EntityFramework.IdentityUser
{
....
}
public class UserManager<TUser> : IDisposable where TUser : global::Microsoft.AspNet.Identity.IUser
{
....
}
Matching Attempt
container.RegisterType(typeof(IUserStore<>), typeof(ApplicationUser));
container.RegisterType(typeof(IDisposable), typeof(UserManager<>));
Error: it is not possible to merge an object of type "Main.Models.ApplicationUser" to enter "Microsoft.AspNet.Identity.IUserStore 1[Main.Models.ApplicationUser]'.
With out mapping, i get this error: The current type, Microsoft.AspNet.Identity.IUserStore1 [Main.Models.ApplicationUser], is an interface and cannot be constructed, are you missing a type mapping?
Scenario 2:
public RegisterController(
IUserDataStorage<HandyGuy> session)
{
this.handySession = session;
}
Type definition
public class HttpUserDataStorage<T> : IUserDataStorage<T>
where T : class
{
public T Access
{
get { return HttpContext.Current.Session[typeof(T).FullName] as T; }
set { HttpContext.Current.Session[typeof(T).FullName] = value; }
}
}
Matching Attempt:
container.RegisterType(typeof(IUserDataStorage<>), typeof(HttpUserDataStorage<>));
Error: no errors. But I always have null in handySession.Access
Habo source
share