I'm trying to use ninject with asp.net identity and currently I was doing the following for the bindings:
kernel.Bind(typeof(IUserStore<>)).To(typeof(UserStore<>));
Here you have the classes definitions:
public interface IUser : IUser<string>
public interface IUserStore<TUser> : IUserStore<TUser, string>, IDisposable where TUser : class, IUser<string>
public class IdentityUser : IdentityUser<string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>, IUser, IUser<string>, IGenerateKeys
public class UserStore<TUser> : UserStore<TUser, IdentityRole, string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim>, IUserStore<TUser>, IUserStore<TUser, string> where TUser : IdentityUser, new()
public class Context {
public Context(ILogger Logger, Dictionary<string, string> LocalConfig, IUserStore<IUser> UserManager
){...}
}
When I try to do kernel.Get<Context>()
I get the error about not being able to cast IUserStore to UserStore.
Unable to cast object of type 'UserStore`1[IdentityUser]' to type 'Microsoft.AspNet.Identity.IUserStore`1[Microsoft.AspNet.Identity.IUser]'.
I don't really understand why this is not working but in fact trying the following IUserStore<IdentityUser> dummy = new Store<IdentityUser>()
gives no compilation error, but this IUserStore<IUser> dummy = new Store<IdentityUser>()
does, but i can't understande why since IdentityUser implements IUser.
Anyone had any similar problem?