I have a composite structure in my domain where the node (Allocation) sheet has a DurationChanged event that I would like to use at the top of the structure of the presentation layer view model (in TimeSheetViewModel), and I'm wondering what is the best way to get to it.
Options that come to mind include:
- Subscribe to it in TimeSheetComposite. Each composite ultimately consists of Allocations, and TimeSheetComposite is the model for TimeSheetViewModel. I also seem to need an event in TimeSheetComposite that will fire when the DurationChanged child event fires; TimeSheetViewModel will subscribe to the latest event.
- Ignore the DurationChanged event and simply follow the INPC chain that bubbles up to the TimeSheetViewModel when AllocationViewModel.Amount is changed. I would not have useful information, in particular the old amount before editing, but I can calculate the necessary final results, if necessary, cheap enough.
- Make the DurationChanged Event a Domain Event ; I am not currently using domain events, but I'm sure this is a concept, and it looks like there is enough code in the Udi article to start with it.
- Create some kind of event aggregator to publish and subscribe to DurationChanged. I'm still not quite sure what the difference is between events in the domain and event aggregators, and whether they are free or alternative approaches to solving the same thing. the implementation here using Rx looks promising .
In this design, TimeSheetViewModel needs to know when Allocation.Duration has changed so that it can get a new total of all durations by date.
How can you provide a DurationChanged notification?
Cheers
Berryl
Composite Domain Structure and Event

Presentation Layer Structure

source share