Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

We have IAppContext which is injected into ViewModel.
This service contains shared data: global filters and other application wide properties.

But there are cases when data is very specific. For example one VM implements Master and the second one - Details of selected tree item. Thus DetailsVm must know about the selected item and its changes.

We can store this information either in IAppContext or inside each concerned VM. In both cases update notifications are sent via Messenger.

I see pros and cons for any of the approaches and can not decide which one is better.

1st:
+ explicitly exposed shared proerties, easy to follow dependencies
- IAppContxt becomes cluttered with very specific data.

2nd:
the exact opposite of the first and more memory load due to data duplication.

May be someone can offer design alternatives or tell that one of the variants is objectively superior to the other cause I miss something important?

share|improve this question
3  
In most cases for me like this, MasterVM contains a property for DetailVM, and DetailVM.CurrentItem gets set when MasterVM.SelectedItem changes. The ViewModels are my application, so it makes sense that they be connected in situations such as a storing TreeView data –  Rachel Dec 3 '12 at 15:22
    
Like @Rachel, I see a parent-child relationship here between the master VM and its detail VM, and I would architect the two in that way. –  KeithS Jul 10 '13 at 2:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.