Ninject和ASP.NET Identity 2.0 [英] Ninject and ASP.NET Identity 2.0

查看:58
本文介绍了Ninject和ASP.NET Identity 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将ASP.NET Identity Entity Framework程序包从1.0升级到了2.0,现在Ninject绑定之一已损坏:

I just upgraded the ASP.NET Identity Entity Framework package from 1.0 to 2.0 and one of the Ninject bindings is now broken:

kernel.Bind<IUserStore<User>>().To<UserStore<User>>();
kernel.Bind<UserManager<User>>().ToSelf();
kernel.Bind<IRoleStore<IdentityRole>>().To<RoleStore<IdentityRole>>();
kernel.Bind<RoleManager<IdentityRole>>().ToSelf();

倒数第二个是在编译时出现此错误:

The second last one is giving this error on compile:

在通用类型或方法"Ninject.Syntax.IBindingToSyntax.To()"中,类型"Microsoft.AspNet.Identity.EntityFramework.RoleStore"不能用作类型参数"TImplementation".

The type 'Microsoft.AspNet.Identity.EntityFramework.RoleStore' cannot be used as type parameter 'TImplementation' in the generic type or method 'Ninject.Syntax.IBindingToSyntax.To()'.

没有从'Microsoft.AspNet.Identity.EntityFramework.RoleStore'到'Microsoft.AspNet.Identity.IRoleStore'的隐式引用转换.

There is no implicit reference conversion from 'Microsoft.AspNet.Identity.EntityFramework.RoleStore' to 'Microsoft.AspNet.Identity.IRoleStore'.

这些是所涉及类的一些声明:

These are some of the declarations of the classes involved:

public interface IRoleStore<TRole> : IRoleStore<TRole, string>, IDisposable where TRole : IRole<string>

public class RoleStore<TRole, TKey, TUserRole> : IQueryableRoleStore<TRole, TKey>, IRoleStore<TRole, TKey>, IDisposable where TRole : IdentityRole<TKey, TUserRole>, new() where TUserRole : IdentityUserRole<TKey>, new()

我不确定是什么原因导致了它破裂?

I'm not sure what has caused it to break?

推荐答案

我们添加了一个新的RoleStore基类,并将用户角色实体类型添加为通用类型,因此也许可以尝试

We added a new base RoleStore class and added the user role entity type as a generic type, so perhaps try

kernel.Bind<IRoleStore<IdentityRole, string>>().To<RoleStore<IdentityRole, string, IdentityUserRole>>();

这篇关于Ninject和ASP.NET Identity 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆