0

In my domain model I've got two principal entities: User and Event, both which I've decided to make aggregate roots. Users and Events have a one-to-many relationship wherein Users can create several events. However, an Event does not necessarily have a corresponding User (i.e. created by the admin) and has its own set of properties / entities. An Event should be able to be manipulated independently of a User.

Given these relationships, I'm wondering if I've done something wrong in my modelling? Is it alright to have the User aggregate root reference another aggregate root? Given that an Event can be manipulated independently of a User, would that introduce any risks to the User's consistency?

3
  • You can reference any object you like (that's accessible from the ARs point of view, including other ARs), but by saying that User is an aggregate (with the User class/entity being its root), you're saying that there's a consistency boundary around User that explicitly doesn't include Events. That is, you are saying that Events and their associated users are not expected to be consistent at all times. Is this valid? IDK. Do they have to be consistent within milliseconds? Is it OK if they become consistent in a few minutes, when the user refreshes the page? Only you can answer that. 1/2 Apr 28 at 4:42
  • The other thing is, during conceptual design, a reference from one object to another just means that the first object has some way to refer to the other object. How you actually implement that should be based on your needs/constraints. Maybe it's an actual direct reference, maybe it's an index into some list, maybe it's just an ID of the other object, or maybe it's a data structure that holds a ref/index/ID + an aggregate-local copy of some data of interest that strictly respects aggregate's invariants, until some external consistency mechanism kicks in. 2/2 Apr 28 at 4:42
  • ’An Event should be able to be manipulated independently of a User’. Even if that event was created by another user?
    – Rik D
    Apr 28 at 15:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.