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

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