领域事件 v 事件聚合器 v...其他

发布于 2024-10-29 09:54:09 字数 1209 浏览 0 评论 0原文

我的域中有一个复合结构,其中叶节点(分配)有一个 DurationChanged 事件,我想在表示层视图模型结构(在 TimeSheetViewModel 中)的顶部使用该事件,我想知道最好的方法是什么去实现它。

我想到的选项包括:

  1. 在 TimeSheetComposite 中订阅它。每个组合最终都由分配组成,而 TimeSheetComposite 是 TimeSheetViewModel 的模型。看来我还需要 TimeSheetComposite 中的一个事件,当触发子 DurationChanged 事件时该事件会被触发; TimeSheetViewModel 将订阅后一个事件。
  2. 忽略 DurationChanged 事件,只遵循当 AllocationViewModel.Amount 更改时冒泡到 TimeSheetViewModel 的 INPC 链。我不会有有用的信息,特别是编辑之前的旧金额,但如果有必要,我可以足够便宜地计算所需的最终结果。
  3. 将 DurationChanged 事件设为域事件;我目前不使用域事件,但我确实喜欢这个概念,而且 Udi 的文章中似乎有足够的代码可以开始使用它。
  4. 设置某种事件聚合器来发布和发布订阅 DurationChanged。我还不太确定领域事件和事件聚合器之间有什么区别,以及它们是否是解决同一问题的补充方法或替代方法。 这里使用 Rx 的实现看起来很有希望

在此设计中,TimeSheetViewModel 需要知道 Allocation.Duration 何时发生更改,以便它可以按日期获取所有分配持续时间的新总计。

您将如何提供 DurationChanged 通知?

干杯,
Berryl

域复合结构与事件

在此处输入图像描述

表示层结构

在此输入图像描述

I have a composite structure in my domain where the leaf node (Allocation) has a DurationChanged event that I would like to use at the top of my presentation layer view model structure (in the TimeSheetViewModel), and I am wondering what the best way is to get to it.

Options that come to mind include:

  1. Subscribe to it in the TimeSheetComposite. Each composite is ultimately composed of Allocations, and the TimeSheetComposite is the Model to the TimeSheetViewModel. It seems I would also need an event in the TimeSheetComposite that gets fired when a child DurationChanged event is fired; the TimeSheetViewModel would subscribe to the latter event.
  2. Ignore the DurationChanged event and just follow the INPC chain that bubbles up to the TimeSheetViewModel when AllocationViewModel.Amount is changed. I wouldn't have a useful piece of information, specifically the old Amount prior to the edit, but I can calculate the needed end results cheaply enough if necessary.
  3. Make the DurationChanged event a Domain Event; I do not currently use domain events, but I sure like the concept and it looks like there is enough code in Udi's article to get started with it.
  4. Set up some sort of Event Aggregator to publish & subscribe to DurationChanged. I am not very sure yet what the difference is yet between Domain Events and Event Aggregators are, and whether they are complimentary or alternative approaches to solving the same thing. The implementation here using Rx looks promising.

In this design, the TimeSheetViewModel needs to know when an Allocation.Duration has changed so it can get a new total of all allocation durations by date.

How would you provide the DurationChanged notice?

Cheers,
Berryl

Domain Composite structure & event

enter image description here

Presentation layer structure

enter image description here

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

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

发布评论

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

评论(1

铜锣湾横着走 2024-11-05 09:54:09

我最终侦听 (TimeSheet)Composite 中的叶事件,然后基本上在那里重新抛出一个类似的事件,以便 (TimeSheet)ViewModel 轻松侦听它。

当我更好地理解 DomainEvents / EventAggregators 时,我将重新审视这一点。

干杯,
贝里尔

I wound up listening for the leaf event in the (TimeSheet)Composite, and then essentially re-throwing a similar event there to make it easy for the (TimeSheet)ViewModel to listen to it.

When I understand DomainEvents / EventAggregators better I will revisit this one.

Cheers,
Berryl

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