JD.
JD.

Reputation: 15561

How do I access an entity behind my aggregate root?

I am into my first week of DDD and have a couple of entities with aggregate roots defined.

I read that no external entity outside of an aggregate can reference an entity in an aggregate, so the external entity has to reference the aggregate root.

Well, unless I have modelled my solution incorrectly I need a reference to an entity behind the aggregate root. How do I handle this situation or do I have to remodel my domain to avoid this situation?

JD

Upvotes: 1

Views: 425

Answers (2)

Rahim Lotfi
Rahim Lotfi

Reputation: 59

You can use the Dynamic Aggregate Dynamic aggregate allows you to combine aggregates and load them dynamically at runtime. Dynamic aggregate makes it possible to load data from different aggregates at high speed without changing the primary aggregates. When reading data from different aggregates, it is recommended to use Dynamic aggregate to reduce the number of I/O.

For more details see this repository. git Repository

Upvotes: 0

Dennis Traub
Dennis Traub

Reputation: 51694

You probably could refine your model. If an external reference to an entity inside your aggregate is required, then that is a strong indicator that the internal entity might be an aggregate root itself.

This of course is general advice since I don't know anything about your specific model.

For great advice concerning aggregate design, have a look at this paper by Vaughn Vernon. In Part I, "Modeling of an Aggregate", he specifically addresses aggregate granularity which I found very enlightening.

Upvotes: 3

Related Questions