Ninject和ASP.NET Identity 2.0

8

我刚刚将ASP.NET Identity Entity Framework包从1.0升级到2.0,其中一个Ninject绑定现在已经失效:

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

倒数第二个编译时会出现以下错误:

类型“Microsoft.AspNet.Identity.EntityFramework.RoleStore”无法用作泛型类型或方法“Ninject.Syntax.IBindingToSyntax.To()”中的类型参数“TImplementation”。

从“Microsoft.AspNet.Identity.EntityFramework.RoleStore”到“Microsoft.AspNet.Identity.IRoleStore”没有隐式引用转换。

以下是涉及类的一些声明:

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()

我不确定是什么原因导致它出现故障了?

1个回答

10

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

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

工作完美!谢谢。 - carzogliore

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接