Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

11
  • 2
    Just to point out: the added difficulty here is that you have a secret link between your different domain aggregates. If you load Tom as a person (which includes their friend list), and you also load Andy (which includes their friend list), and Tom now adds Andy as a friend, that means that you're expecting Andy's list to update and suddenly also contain Tom. This is not something you will find prescribed in general DDD documentation as it is a very special case. I haven't had the time to investigate for a full answer but I suspect that you will need to make friendships have their own context. Commented Sep 8, 2023 at 3:02
  • Well it's a made up situation, I mostly tried to come up with the simplest example. The question isn't about this specific scenario but more about how to deal with the fact that objects will always be partially loaded and the domain layer needs to be in sync with the infrastructure layer in order to avoid error Commented Sep 8, 2023 at 4:01
  • 1
    The point I was getting at is that this is a problem of your own making, this is a nested structure that is very likely an infinite one (to the point of exhaustion of having loaded all your users). You don't want this, but you also don't want any of the additional work that the alternatives present. Something's gotta give, and we can't decide which poison is best to pick. There are myriad ways of modeling this and I'm not convinced that the current question is focused enough towards a particular approach. Every approach has wildly different pros and cons and this requires more analysis. Commented Sep 8, 2023 at 5:22
  • 2
    What I have found that helps is not holding the whole objects, just the ids. Ask yourself why you actually need to describe your domain entity with all the friends' objects. Where exactly does your BL use it? is it common or do you only use it occasionally? Your User entity has friends, ok, but what if the entity itself will hold only the ids of the friends? Commented Sep 8, 2023 at 10:25
  • 1
    I almost exclusively use the domain layer for write operations, and yes I'm already implementing the CQRS pattern but I don't see how that is relevant to how I design my domain layer? Commented Sep 12, 2023 at 17:40