views:

125

answers:

1

I have a few (hopefully) simple questions about aggregate roots in domain driven design:

  1. Is it okay to have an aggregate root as a property of another aggregate root?
  2. Is it okay to have a given entity inside two or more aggregate roots?

My final question is a bit more involved. I have a website that has a few entities that really belong to a "website" aggregate root. They are 'News', 'Products', and 'Users'. There isn't a 'Website' table in the database, but a 'Website' seems like a good aggregate root for these three entities. How is this usually achieved?

Thanks!

+1  A: 

Do you have any consistency rules spanning the whole website (concerning multiple news products and usesrs)? If not, these entities (news, products, users) are good candidates for being you aggregate roots.

Aggregate root main function is to provide consistency and transaction semantics boundary.

To answer you questions:

  1. Yes, it is ok as long as this referred aggregate root is not modified during any operation of the containing AR. This is connected to the consistency boundaries: operations spanning multiple aggregates are not guarantied to produce consistent results so they should be avoided

  2. No, an entity (which is not AR) can be a part of only one aggregate.

Szymon Pobiega
Thanks for your answers. Thinking about the news, products, and user, it actually seems like users belong to a different aggregate root, and since news and products aren't really related, they are their own aggregate roots. Your answers to 1 and 2 also make sense as I'm working through my domain.
Robert