What is the good way of sharing specific data between ViewModels

Posted by voroninp on Programmers See other posts from Programmers or by voroninp
Published on 2012-12-03T13:01:31Z Indexed on 2012/12/03 17:18 UTC
Read the original article Hit count: 161

Filed under:
|
|

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?

© Programmers or respective owner

Related posts about design-patterns

Related posts about wpf