Dependency injection RoleStore型<;IdentityRole>;不可分配给服务IRoleStore<;IRole>;

Dependency injection RoleStore型<;IdentityRole>;不可分配给服务IRoleStore<;IRole>;,dependency-injection,autofac,asp.net-mvc-5,entity-framework-6,Dependency Injection,Autofac,Asp.net Mvc 5,Entity Framework 6,我正在尝试使用Autofac为使用MVC5和EF6的项目设置依赖项注入 我很难弄清楚如何正确地解耦EntityFramework.RoleStore实现。 我希望只依赖于Identity.IRoleStore,但我知道对于泛型类,我需要指定具体的实现,而不是接口 这就是我所尝试的: builder.RegisterType<IdentityRole>().As<IRole>(); builder.RegisterType<RoleMa

我正在尝试使用Autofac为使用MVC5和EF6的项目设置依赖项注入

我很难弄清楚如何正确地解耦EntityFramework.RoleStore实现。
我希望只依赖于Identity.IRoleStore,但我知道对于泛型类,我需要指定具体的实现,而不是接口

这就是我所尝试的:

        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>>()));
builder.RegisterType().As();
RegisterType();
builder.RegisterType().As();
Register(c=>newrolemager(c.Resolve());
完整错误消息:

类型“Microsoft.AspNet.Identity.EntityFramework.RoleStore
1[Microsoft.AspNet.Identity.EntityFramework.IdentityRole]”不可分配给服务“Microsoft.AspNet.Identity.IRoleStore
1[[Microsoft.AspNet.Identity.IRole,Microsoft.AspNet.Identity.Core,Version=1.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35]”


派对有点晚了,但这对我来说对Autofac有效:

builder.RegisterType<RoleStore<IdentityRole>>().As<IRoleStore<IdentityRole, string>>();
builder.RegisterType().As();
我的完整模块供参考:

builder.RegisterType<UserStore<ApplicationUser>>().As<IUserStore<ApplicationUser>>();
builder.RegisterType<RoleStore<IdentityRole>>().As<IRoleStore<IdentityRole, string>>();
builder.RegisterType<ApplicationUserManager>();
builder.RegisterType<ApplicationRoleManager>();  
builder.RegisterType().As();
builder.RegisterType().As();
RegisterType();
RegisterType();
我正在为UserManager和RoleManager使用包装器

public class ApplicationUserManager : UserManager<ApplicationUser>
{
    public ApplicationUserManager(IUserStore<ApplicationUser> store)
        : base(store)
    {
    }
}

public class ApplicationRoleManager : RoleManager<IdentityRole>
{
    public ApplicationRoleManager(IRoleStore<IdentityRole, string> roleStore)
        : base(roleStore)
    {            
    }       
}
公共类应用程序管理员:用户管理员
{
公共应用程序服务器管理器(IUserStore存储)
:基地(商店)
{
}
}
公共类应用程序RoleManager:RoleManager
{
公共应用程序角色管理器(IRoleStore角色存储库)
:底座(roleStore)
{            
}       
}