좋아는, 이후 많은 발굴 및 운 발견 - 그것은 Microsoft.AspNet.Identity.Core는, 특히, IUserRoleStore<TUser>
및 IUserPasswordStore<TUser>
하는 모두 (시행) "상속"몇 가지 다른 인터페이스와 함께 제공 IUserStore 밝혀 <TUser>.
그래서 우리는 역할 관리 기능을 원한다면, 우리는 IUserRoleStore<TUser>
을 구현 :
이
class MyUser : IUser
{
// Additional properties and functions not shown for brevity.
}
class MyUserStore : IUserRoleStore<MyUser>
{
public bool IsInRole(string username, string role)
{
// Implementation not show for brevity.
}
/* We would then implement the rest of the required functions.
We would have a data context here that has access to users,
user-roles, and roles.
*/
}
이제 우리는 UserManager<TUser>
에 MyUserStore
를 전달할 수 MyUserStore
는 IUserStore<TUser>
인 IUserRoleStore<TUser>
이기 때문에 :
UserManager<MyUser> UM = new UserManager<MyUser>(new MyUserStore());
I 그런 다음 UserManager<TUser>
의 소스 코드가 리플렉션을 사용하여 저장소가 생성시 전달되었는지 여부를 확인합니다. 또는 역할 검사 (IUserRoleStore<TUser>
을 구현하는 경우) 또는 암호 설정/재설정 (IUserPasswordStore<TUser>
을 구현하는 경우)을 수행 할 수 있도록 IUserStore<TUserStore>
의 "하위 인터페이스"중 하나를 구현합니다.
대부분의 문서 (MVC 자습서 등)가이 정보를 제공하지 않기 때문에 유용하다고 생각합니다. Microsoft 012.AspNet.Identity.EntityFramework의 UserStore<TUser>
구현을 사용하라는 메시지가 표시됩니다. 사용자 정의 User
객체 (예 : IUser
)를 전달하면됩니다.
그것은 그것이 어떻게 작동하는지 excatly합니다. https://github.com/aspnet/Identity에서 소스 코드를 찾을 수 있습니다. 그들은'var cast = Store as IUserRoleStore; '을 사용하여 당신의 전달 된 상점이'IUserRoleStore '을 구현하는지 확인합니다. –
qbik