简体   繁体   中英

How to communicate between linked entities?

I have entity that holds multiple other entities. When some event occurs in one of those inner entities then other "siblings" should be able to pick up that event.

I would like to avoid public methods on entities that are used as event notification receivers orchestrated by some other "non local layer".

I would also like to avoid infrastructure details as much as possible.

Is there a common practice/pattern for behavior like this?

You say that the entity 'holds' other entities. My answer differs depending on what you mean by that.

If you mean that the entity is an aggregate root and the held entities are children, then nobody should be directly interacting with those children. They should interact with the aggregate, and the aggregate can handle this coordination you're looking for.

If the entity has foreign keys to other aggregates, then you should use domain events as mentioned. Domain events are not from another layer - they are part of the domain itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM