c# - Ninject 和 ASP.NET Identity 2.0

标签 c# entity-framework ninject asp.net-identity

我刚刚将 ASP.NET Identity Entity Framework 包从 1.0 升级到 2.0,其中一个 Ninject 绑定(bind)现已损坏:

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 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'.

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

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

我不确定是什么导致它坏了?

最佳答案

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

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

关于c# - Ninject 和 ASP.NET Identity 2.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22774803/

相关文章:

c# - 如何找到集合的所有分区

c# - 我将如何使用反射来调用具有特定自定义属性的所有方法?

c# - 如何使用 Entity Framework 保证代码与派生字段一致

Ninject transient 范围

ninject - 如何通过 Ninject 使用方法注入(inject)?

c# - 另一种管理这种依赖的方法

C# Windows 窗体 - 使用 MultiSelect、OpenFileDialog 和 FileBrowserDialog 选择并复制多个文件

c# - 调用 IStorage 的 EnumElements 时发生访问冲突

c# - 无法将类型 A 转换为类型 B。LINQ to Entities 仅支持转换 EDM 原语或枚举类型

c# - Entity Framework 代码优先与数据库优先 : Trap Relationship Constraint Problems