CQRS 事件版本控制

发布于 2024-08-26 20:52:46 字数 224 浏览 3 评论 0原文

版本控制
如果您的活动发生变化,您将创建该活动的新版本,并保留旧版本。为了使域代码表单因处理所有版本的事件而变得臃肿,您基本上会引入一个组件,将事件从以前的版本转换为新版本,然后将它们应用到域上。请记住,事件是在您的域中实际发生的事情,因此在大多数情况下,已弃用事件中的信息很有价值。

我还没有找到任何这方面的例子。

有什么帮助吗?

Versioning
If your events changes you would create a new version of that event, and keep the old ones. To keep your domain code form being bloated with handling of all versions of events you would basically introduce a component that converts your events from previous to newer versions, and then apply them on the domain. Remember that events are things that actually happened in your domain so in most cases the information in deprecated events are valuable.

I still haven't found any example of this.

Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

下壹個目標 2024-09-02 20:52:46

处理事件转换有两种主要方法。两者都发生在事件反序列化期间:

  1. 您可以添加带有版本号的新类(SomethingHappened、SomethingHappened2、SomethingHappened3)。反序列化器将实例化并填充该类,将其传递给转换器以获得更高版本中的相同事件,此处为 SomethingHappened3。
    问题之一是您还必须更新事件处理程序才能使用该事件的最新版本。
    为了缓解这种情况,您可以使用“SomethingHappened”始终是最后一个版本的约定。当转到 v2 时,将 SomethingHappened 重命名为 SomethingHappened1 并创建一个将成为 v2 的 SomethingHappened。为此,您需要控制从序列化事件创建的类,因为序列化类名称不包含版本号,您应该将其存储在一边。

  2. 转换器将接收一个文档(一棵树,如 Xml 文档或 Json 对象),并修改它以提供构建最新版本所需的信息,而不是在代码中保留类的每个版本。

所有这一切都取决于您对反序列化管道的控制。

There are two main ways to handle event conversions. Both happen during event deserialization :

  1. You can add new classes with version numbers (SomethingHappened, SomethingHappened2, SomethingHappened3). The deserializer will instanciate and populate the class, the pass it to a converter to get the same event in its higher version, here SomethingHappened3.
    One of the problem is that you'll have to update also event handlers to use the last version of the event.
    To mitigate this, you can use a convention that SomethingHappened is always the last version. When going to v2, rename SomethingHappened as SomethingHappened1 and create a SomethingHappened that will be the v2. To do that you need to have control on the classes created from serialized event since the serialized class name will not contain the version number, you should store it aside.

  2. Instead keeping every version of the classes in your code, the converter will receive a Document (a tree, like an Xml document or JSon object) and will modify it to provide information needed to build the last version.

All this depends on the control you have on your deserialization pipeline.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文