请提问,如何增加在Ninject.Web.Common绑定?
我对角色的实体
public class AppRole : IdentityRole
{
public AppRole() : base() { }
public AppRole(string name)
: base(name)
{ }
}
和经理
public class AppRoleManager : RoleManager<AppRole>
{
public AppRoleManager(RoleStore<AppRole> store) : base(store)
{ }
}
我想,生成方法在Ninject做的像我一样的的UserManager和SignUpManager
我Ninject常见
private static void RegisterServices(IKernel kernel)
{
System.Web.Mvc.DependencyResolver.SetResolver(new Infrastructure.NinjectDependencyResolver(kernel));
kernel.Bind<IRoleStore<IdentityRole, string>>().To<RoleStore<IdentityRole, string, IdentityUserRole>>();
kernel.Bind<RoleManager<IdentityRole, string>>().ToSelf();
}
kernel.Bind<IRoleStore<IdentityRole, string>>().To<RoleStore<IdentityRole, string, IdentityUserRole>>();
kernel.Bind<RoleManager<IdentityRole, string>>().ToSelf();
我改变这哪里错了绑定
kernel.Bind<AppRoleManager>().ToSelf();
kernel.Bind<IRoleStore<IdentityRole, string>>().To<RoleStore<IdentityRole, string, IdentityUserRole>>();
并在构造函数中的问题是关闭的。 (谢谢亚历山大)
但鉴于问题
私人IUserManagerRepository的UserManager;私人只读AppRoleManager UserRole的;
public RoleController(IUserManagerRepository userManager, AppRoleManager userRole)
{
this.userManager = userManager;
this.userRole = userRole;
}
// GET: Role
public ActionResult Index()
{
return View(userRole.Roles);
}
而我的看法
@using Domain.IdentityManager
@using Domain.Entities
@model IEnumerable<AppRole>
<div class="panel panel-primary">
<div class="panel-heading">Roles</div>
<table class="table table-striped">
<tr>
<th>ID</th>
<th>Название</th>
<th>Пользователи</th>
<th style="min-width: 150px"></th>
</tr>
@foreach (AppRole role in Model)
{
<tr>
<td>@role.Id</td>
<td>@role.Name</td>
<td>
@if (role.Users == null || role.Users.Count == 0)
{
@: Нет пользователей в этой роли
}
else
{
}
</td>
}
</table>
为了解决这个错误,你必须做出RoleController
构造函数及其参数类型一致的可访问性。由于构造函数是public
它的参数必须是public
为好。编译器抱怨AppRoleManager<IdentityRole>
所以我们需要看看它。显然AppRoleManager
是public
,它看起来像IdentityRole
只是不public
在此处键入。因此,更新其声明
public class IdentityRole //