Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ninject and ASP.NET Identity 2.0

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:

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

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?

like image 816
user380689 Avatar asked Apr 01 '14 00:04

user380689


1 Answers

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>>();
like image 114
Hao Kung Avatar answered Oct 05 '22 19:10

Hao Kung