简体   繁体   English

链接实体之间如何通信?

[英]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. 域事件不是来自另一层-它们是域本身的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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