I am a beginner to DDD and have a question on how to implement to authorization invariants for a particular domain use case.
I have two subdomains: Membership and Identity. Identity handles authentication and managing user and roles.
The subdomain in question is Membership. Members can have a number of statuses. When activating a member, there are three invariants:
- Chapter Administrators can only activate a member in their chapter
- Chapter Administrators can only activate inactive members.
- System Administrators can activate any member from any status.
Users have roles. The roles for this situation are System Administrator and Chapter Administrator(for a single chapter).
So I have an application service. User Id is stored in .Net Identity, but I feel like keeping the application service unaware of .Net Identity is a good idea?
public void ActivateMember(UserId userId, MemberId memberId)
{
//This handles invariants 1 & 3
memberAccess.DoesUserHaveAccessToMember(userId, memberId);
//But how to I handle 2?
//here is the call into the domain
commands.Handle(new ActivateMember(memberId);
}
How to handle 2? The command handler is a domain service that just loads the member, calls its activate member and persists it back. Should authentication services from the Identity domain be pushed that far down? I could implement 2 in the above class, but then I have to load the member twice from the repository. Is that bad?