When i try to use Asp.Net Identity RoleStore and use StructureMap as DI container, the UserStore works fine, but the RoleStore throws up an error at compilation itself.
//works fine
cfg.For<IUserStore<ApplicationUser>>().Use<UserStore<ApplicationUser>>();
//does NOT work
cfg.For<IRoleStore<IdentityRole>>().Use<RoleStore<IdentityRole>>();
throws the following error
The type 'Microsoft.AspNet.Identity.EntityFramework.RoleStore' cannot be used as type parameter 'TConcreteType' in the generic type or method 'StructureMap.Configuration.DSL.Expressions.CreatePluginFamilyExpression.Use()'. There is no implicit reference conversion from 'Microsoft.AspNet.Identity.EntityFramework.RoleStore' to 'Microsoft.AspNet.Identity.IRoleStore'.
Because RoleStore<TRole>
is not implemented from IRoleStore<TRole>
. Actually it is implemented from IRoleStore<TRole, TKey>
. Therefore try this instead:
cfg.For<IRoleStore<IdentityRole,string>>().Use<RoleStore<IdentityRole>>();