question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Isn't it a problem that you add entities to an aggregate from a different aggregate?

See original GitHub issue

https://github.com/citerus/dddsample-core/blob/master/src/main/java/se/citerus/dddsample/application/impl/BookingServiceImpl.java#L38

    final TrackingId trackingId = cargoRepository.nextTrackingId();
    final Location origin = locationRepository.find(originUnLocode);
    final Location destination = locationRepository.find(destinationUnLocode);
    final RouteSpecification routeSpecification = new RouteSpecification(origin, destination, arrivalDeadline);

    final Cargo cargo = new Cargo(trackingId, routeSpecification);

    cargoRepository.store(cargo);

Here the Location is an entity, actually it looks like an aggregate root. Still you pass it as a parameter to the RouteSpecification. Afaik. aggregates cannot access each other directly. You should have added only a verified LocationId to the RouteSpecification, which is not necessarily the UnLocode you use for finding it. But correct me if I am wrong.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
chrisselwyncommented, Mar 4, 2022

I too have recently started on the path of learning about DDD. I am finding that this example is very confusing because it appears to break the rules that I have been reading about in Eric Evans’s book and Vaughn Vernon’s book.

For example, just looking at the cargo root aggregate, I see that it imports several entities from other root aggregates. Some of these are not even roots of their respective aggregates.

Here is a list of such cases that I have found :-

  • handling.HandlingHistory used in Cargo.java Delivery.java

  • handling.HandlingEvent used in Delivery.java Itinerary.java HandlingActivity.java

  • voyage.Voyage used in HandlingActivity.java Delivery.java Leg.java

  • location.Location used in Cargo.java Delivery.java HandlingActivity.java Itinerary.java Leg.java RouteSpecification.java

Is there something that I am missing that makes it OK for these classes to import classes (including non-root aggregate classes) from other aggregates? It maybe that my understanding is wrong. In which case I would love to know how!

1reaction
npathaicommented, Jul 15, 2021

@inf3rno My apologies, I didn’t go through the whole comment, but there is one thing I read recently. It’s that DDD is only good if the domain logic has complexity and not a good fit if the technology is complicated. It only works in case of domain complexity. Maybe that’s something you can review, make sure you are not using incorrect approach.

Otherwise to get help on DDD, you can try reaching out at: DDD-CQRS-ES Slack. At the very least you can ask there for better community where you can ask this question. And anyways it’s a good community to be a part of if you are interested in DDD.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Are entity classes exclusive to one aggregate - Stack Overflow
Entity classes could theoretically be shared between 2 aggregates, but, by the same reasoning, only if the set of entity instances in an...
Read more >
DDD: Re-assign an entity from one aggregate to other
Traditionally, the recommendation has been to deal with cross-aggregate domain operations in a Domain Service.
Read more >
An In-Depth Understanding of Aggregation in Domain-Driven ...
The objects inside the aggregation, whether they are entity objects or value objects, only need to ensure that the internal Ids are unique....
Read more >
What Are Aggregates In Domain-Driven Design? - James Hickey
Aggregates are one of the most misunderstood concepts in domain-driven design. Is it just a clump of entities & objects? Or something more?...
Read more >
Classes internal to an aggregate: entities or value objects?
We can replace one with another of the same properties and nobody will notice. So, how to resolve this problem? Are such classes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found