领域事件 v 事件聚合器 v...其他
我的域中有一个复合结构,其中叶节点(分配)有一个 DurationChanged 事件,我想在表示层视图模型结构(在 TimeSheetViewModel 中)的顶部使用该事件,我想知道最好的方法是什么去实现它。
我想到的选项包括:
- 在 TimeSheetComposite 中订阅它。每个组合最终都由分配组成,而 TimeSheetComposite 是 TimeSheetViewModel 的模型。看来我还需要 TimeSheetComposite 中的一个事件,当触发子 DurationChanged 事件时该事件会被触发; TimeSheetViewModel 将订阅后一个事件。
- 忽略 DurationChanged 事件,只遵循当 AllocationViewModel.Amount 更改时冒泡到 TimeSheetViewModel 的 INPC 链。我不会有有用的信息,特别是编辑之前的旧金额,但如果有必要,我可以足够便宜地计算所需的最终结果。
- 将 DurationChanged 事件设为域事件;我目前不使用域事件,但我确实喜欢这个概念,而且 Udi 的文章中似乎有足够的代码可以开始使用它。
- 设置某种事件聚合器来发布和发布订阅 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:
- 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.
- 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.
- 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.
- 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
Presentation layer structure
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终侦听 (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