域事件应该有多精细? [英] How granular should a domain event be?

查看:78
本文介绍了域事件应该有多精细?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道域事件的粒度如何?

I am wondering how granular should a domain event be?

例如,我有一些简单的事情,例如更改配置文件中的firstName,secondName和电子邮件地址页。我应该拥有3个不同的域事件还是只有一个?

For example I have something simple, like changing the firstName, the secondName and the email address on a profile page. Should I have 3 different domain events or just a single one?

通过添加新功能时的粗粒度域事件,我必须创建该事件的新版本,因此我必须添加新的事件类型,或将事件版本存储在事件存储中。通过细粒度的域事件,我没有这些问题,但是我有太多的小类。您如何看待,在这种情况下的最佳实践是什么?

By coarse grained domain events when I add a new feature, I have to create a new version of the event, so I have to add a new event type, or store event versions in the event storage. By fine grained domain events I don't have these problems, but I have too many small classes. What do you think, what is the best practice in this case?

推荐答案

许多类有什么问题?真的,为什么这么多开发者害怕开设过多的课程?您可以根据需要定义任意多个类。

What's the problem with many classes? Really, why so many devs are afraid of having too many classes? You define as many classes as needed.

域事件表示域以某种方式发生了变化。它应包含所有相关信息,并且应考虑到事件也是DTO的事实。您需要明确的事件,但是由开发人员决定事件的粒度或通用性。

A domain event signals that the domain changed in a certain way. It should contain all the relevant information and it should be taken into consideration the fact that an event is also a DTO. You want clear events but it's up to the developer to decide how granular or generic an event is.

大小不是问题,但是如果事件权重为1 MB也许你有问题。而且,类数不是域事件设计标准。

Size is not a concern, however if your event 'weights' 1 MB maybe you have a problem. And the number of classes is not a domain event design criteria.

这篇关于域事件应该有多精细?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆