I'm trying to set up dependency injection with Autofac for project using MVC5 and EF6.
I'm having a hard time figuring out how to decouple correctly the EntityFramework.RoleStore<EntityFramework.IdentityRole> implementation.
I would like have dependency only on Identity.IRoleStore<Identity.IRole> but I'm aware that for generic classes I need to specify the concrete implementation, not the interface.
This is what I tried:
builder.RegisterType<IdentityRole>().As<IRole>();
builder.RegisterType<RoleManager<IRole>>();
builder.RegisterType<RoleStore<IdentityRole>>().As<IRoleStore<IRole>>();
builder.Register(c => new RoleManager<IRole>(c.Resolve<IRoleStore<IRole>>()));
The full error message:
The type 'Microsoft.AspNet.Identity.EntityFramework.RoleStore
1[Microsoft.AspNet.Identity.EntityFramework.IdentityRole]' is not assignable to service 'Microsoft.AspNet.Identity.IRoleStore
1[[Microsoft.AspNet.Identity.IRole, Microsoft.AspNet.Identity.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]'.