在命令处理程序中从 readmodel 请求数据

发布于 2024-12-18 13:44:01 字数 189 浏览 3 评论 0原文

我需要向管理员列表发送一封电子邮件作为回复 从 UI 发送的命令。需要通知的管理员是 从针对读取模型的查询中检索。

目前 - 根据我的理解,我只有一个 选项:在发送命令之前收集所需的管理员并添加 他们(姓名/电子邮件对)到命令。

或者 - 从命令处理程序跨越到读取是否可以接受 模型?感觉不对,但我真的没有看到任何其他方式 做这个?

I have the need to send an email to a list of admins as a response to
a command sent from the UI. The admins that need to be notified are
retrieved from a query against the read model.

At the moment - from my understanding as it stands I only have one
option: gather the required admins before sending the command and add
them (name/email pair) to the command.

Or - is it acceptable to cross from the command handler to the read
model? It doesn't feel right but I don't really see any other way of
doing this?

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

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

发布评论

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

评论(3

陪我终i 2024-12-25 13:44:01

您没有透露任何有关如何实现命令端的信息。我通常在命令处理程序中提供此信息。然后,我根据添加到命令的 ID 查询数据源中的电子邮件和姓名。您不需要通过域模型来执行此操作。如果命令端没有可用的数据,我认为通过服务从读取端收集数据不会有大问题。我不会从域模型中执行此操作。

You don't tell anything about how you have implemented the command side. I usually have this information available in the command handler. I then query the datasource for e-mail and name based on the IDs added to the command. You don't need to go through the domain model to do this. If you don't have the data available on the command side, I don't see a big problem with collecting data from the read side through a service. I would not do this from the domain model.

み零 2024-12-25 13:44:01

您根本无法从您的域访问读取模型,因为您的域是临时的,而不是您的读取模型。您需要拥有在执行命令时获取的电子邮件列表:)

您可以,或者在触发邮件的命令中包含管理员电子邮件列表,然后将其作为事件和时间持久保存,或者您可以您的域实体实例化将获取列表管理电子邮件的其他域实体。

希望这有帮助。

You simply cannot access the read model from your domain as your domain is temporal, not your read model. You need to have the list of email's that were taken athe time of the command :)

You can, or include on the commands that trigger the mail the list of admin's email, It is then persisted as an event and temporal, Or you could have your domain entity instantiating other domain entity that will get the the list admin emails.

Hope this help.

泅人 2024-12-25 13:44:01

假设您的命令正在抛出事件...

对我来说,解决此问题的正确方法是使用单独的事件处理程序来捕获命令的事件并触发电子邮件的发送。您的事件处理程序将查询现有的读取模型以获取管理员列表。

让事情变得简单,因为您的命令处理程序不需要知道向管理员发送电子邮件的需要。

您可以极端地概念上为此拥有一个单独的系统,该系统还处理管理员创建/删除的事件,存储在特定的读取模型中纯粹是为了保存发送电子邮件的管理员列表到。

Assuming your commands are throwing events...

To me the right way to go about this would be to have a separate event handler to capture the command's event and trigger the sending of the email. Your event handler would query the existing read-model for a list of admins.

Keeps things simple as your command handler doesn't need to be aware of this need to email the admins.

You could go the extreme of conceptually having a separate system for this, which also handles your admin-created/deleted events, storing in a specific read-model purely to hold a list of admins to send the email to.

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