检测域对象的更改
有一个实体:客户,如果客户更改了姓名(通过 Web UI),客户服务必须检测到此更改并向管理员发送电子邮件。
现在这个责任应该分配给客户吗?类似于
c.HasChangedName(NewName);其中 c 是对客户的引用
根据对客户实体的此类更改,客户服务可能会执行其他活动。电子邮件只是一个例子。
There is an Entity:Customer and if the Customer changes his name ( via Web UI), the Customer Service must detect this change and send an email to Administrator.
Now should this responsibility be assigned to the Customer? Something like
c.HasChangedName(NewName); where c is a reference to the Customer
There could be other activities undertaken by the CustomerService based on such changes to the Customer entity. Email is just an example.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据我的观点,客户聚合根(我认为它是聚合根而不是实体)应该在
方法调用中发布 CustomerNameChanged 事件。
您可以在 Greg Young 的 github 存储库中查看一些实现示例。
或者,如果不想使用事件源,您可以查看 Udi Dahan 的 发布有关域事件的帖子
By my opinion, Customer aggregate root (I suppose it is an aggregate root and not an entity) should publish CustomerNameChanged event in
method call.
You could look at some implementation sample in Greg Young's github repository.
Or if don't want to use event sourcing you could take a look at Udi Dahan's post about domain events