First just to answer some of the valid questions you raised:
@Kim: true, in this case UserGroup is a kind of long-lived entity. But then isn't it the case with Users, Customers and others? They rarely disable their accounts (if are allowed to at all) too. In this particular case thou, and after consulting our Domain Experts, we're aiming for a user to be able to be part of multiple user groups, which may be created and deleted at will (eg. users who deal with vip clients, users available over the weekend, etc). This seems to suggest that in our domain Users might be more imporant than UserGroups, but of different lifetime (= two ARs).
@Alistair: User and UserGroup being classic not in the DDD-sense, but most (if not all) of the systems we create over here tend to feature these two guys in one form or another. It's may not be the case in other domains, so perhaps I made a sweeping generalization too eagerly. Other than that: that was a lot of questions :-) Very valid ones too. In our case Users are assigned to UserGroups by admins, and UGs have no part in authentication / authorization. Only some algorithms in the system make use of them (like "if vip customer then assign it to one of the users from 'experienced users' group"). So it seems we're dealing with the simpler, manual case rather than Party-type relationships.
@Greg: Brief and to-the-point as usual :-) I liked your idea of considering if a delete should cascade when looking at lifetimes, it makes a lot of sense to my still-ORM-wired brain. In our case, no, as users groups can be created ad-hoc on an as-needed basis, and since users can be part of 0..n UGs, we definitely would not cascade a delete either way.
@Javier: I went through Vernon's series twice before, but for me it's only once I start practicing something that doubts and other thoughts begin to creep in. (Guess Vernon could be like poetry, read over and over again at different stages in your DDD life to deepen your understanding of the subject, much like the Blue Book!) Thanks for reminding me to read it again thou.
@Yves: It talks about the advantage of roles as opposed to groups, which is a very valid point. Hoever, in our case we're going to have both. Roles for authorization, and groups for... well, bunching users into groups like 'experienced users,' 'available over the weekend' etc.
To sum up some of the thoughts and our own revised understanding of the domain.:
- In our case, UserGroup is definitely a domain concept and external to Roles; one that will be used by some of the domain logic, eg. when round-robin distributing new clients to users from a particular group.
- After consulting with domain experts, we now have that UserGroups may be created on an ad-hoc way, and Users may be part of multiple UserGroups at the same time.
- What follows is that we would never cascade a delete either way. We therefore conclude they have different lifetimes.
- Because they share different lifetimes, they are two different Aggregate Roots.
- Implementation detail: as a consequence of U and UG being two ARs, and as suggested earlier by Eric Therond, we only keep List<Guid> UserIds on UserGroups.
It is all much clearer now, and the forest of Aggregate Roots we're surrounded by feels a lot less scary. Thank you for your hints and suggestions, as always they induce thinking, which leads to a deeper understanding of the domain. That in turn makes general rules applied to our domain look a lot more reasonable and exactly the strategies the problem called for.
And apologies for rather lengthy posts, I appreciate you taking the time to help me on my DDD ways all the more.
Regards,
Dawid