Ninject ASP.NET Identity 类型 '.....' 不能用作泛型类型或方法中的类型参数 'TImplementation'

Ninject ASP.NET Identity The type '.....' cannot be used as type parameter 'TImplementation' in the generic type or method

关于我与 Ninject 的绑定,我遇到了一些编译器错误。这是代码:

kernel.Bind<IUserStore<ApplicationUserStore>>().To<UserStore<ApplicationUser, ApplicationRole, int, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>>().InRequestScope();
kernel.Bind<IRoleStore<ApplicationRoleStore>>().To<RoleStore<ApplicationRole, int, ApplicationUserRole>>().InRequestScope();

这些是编译器错误:

Error 5 The type 'MyNamespace.Data.ApplicatonRoleStore' cannot be used as type parameter 'TRole' in the generic type or method 'Microsoft.AspNet.Identity.IRoleStore'. There is no implicit reference conversion from 'MyNamespace.Data.ApplicatonRoleStore' to 'Microsoft.AspNet.Identity.IRole'.

Error 6 The type 'MyNamespace.Data.ApplicatonRoleStore' cannot be used as type parameter 'TRole' in the generic type or method 'Microsoft.AspNet.Identity.IRoleStore'. There is no implicit reference conversion from 'MyNamespace.Data.ApplicatonRoleStore' to 'Microsoft.AspNet.Identity.IRole'.

Error 2 The type 'MyNamespace.Data.ApplicatonUserStore' cannot be used as type parameter 'TUser' in the generic type or method 'Microsoft.AspNet.Identity.IUserStore'. There is no implicit reference conversion from 'MyNamespace.Data.ApplicatonUserStore' to 'Microsoft.AspNet.Identity.IUser'.

Error 3 The type 'MyNamespace.Data.ApplicatonUserStore' cannot be used as type parameter 'TUser' in the generic type or method 'Microsoft.AspNet.Identity.IUserStore'. There is no implicit reference conversion from 'MyNamespace.Data.ApplicatonUserStore' to 'Microsoft.AspNet.Identity.IUser'.

Error 4 The type 'Microsoft.AspNet.Identity.EntityFramework.RoleStore' cannot be used as type parameter 'TImplementation' in the generic type or method 'Ninject.Syntax.IBindingToSyntax.To()'. There is no implicit reference conversion from 'Microsoft.AspNet.Identity.EntityFramework.RoleStore' to 'Microsoft.AspNet.Identity.IRoleStore'.

Error 1 The type 'Microsoft.AspNet.Identity.EntityFramework.UserStore' cannot be used as type parameter 'TImplementation' in the generic type or method 'Ninject.Syntax.IBindingToSyntax.To()'. There is no implicit reference conversion from 'Microsoft.AspNet.Identity.EntityFramework.UserStore' to 'Microsoft.AspNet.Identity.IUserStore'.

默认情况下,asp.net-identity 系统使用 guid 作为主键。我将其更改为使用整数。我可以看到一些关于 Microsoft.AspNet.Identity.IRole<string>.

的错误

编辑: 这些是 类:

public class ApplicationRoleStore : RoleStore<ApplicationRole, int, ApplicationUserRole>
{
    public ApplicationRoleStore(ApplicationDbContext context)
        : base(context)
    { }
}

public class ApplicationUserStore :
    UserStore<ApplicationUser, ApplicationRole, int, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{
    public ApplicationUserStore(ApplicationDbContext context)
        : base(context)
    { }
}

我明白了。以防其他人无意中遇到这个问题,方法如下:

kernel.Bind<IAuthenticationManager>().ToMethod(c => HttpContext.Current.GetOwinContext().Authentication); //.InRequestScope();

kernel.Bind<IRoleStore<ApplicationRole, int>>().To<RoleStore<ApplicationRole, int, ApplicationUserRole>>()
            .WithConstructorArgument("context", context => kernel.Get<ApplicationDbContext>());

kernel.Bind<IUserStore<ApplicationUser, int>>()
            .To<UserStore<ApplicationUser, ApplicationRole, int, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>>()
            .WithConstructorArgument("context", context => kernel.Get<ApplicationDbContext>());

不确定 IAuthenticationManager 是否应该是 InRequestScope,但现在我忽略了那部分。

对于经理,您会这样:

kernel.Bind<UserManager<ApplicationUser, int>>().ToSelf().InRequestScope();
kernel.Bind<RoleManager<ApplicationRole, int>>().ToSelf().InRequestScope();