What do you do with ModelView files growing in an MVVM application?

I am writing an MVVM application, and one of the screens is quite large in size. The screen also supports an object that has several lists of other objects that are also edited in the context of a transaction.

I split the views into several user controls. The model is divided into different types of classes. The problem is the ViewModel. Since it aggregates information from several types of objects and makes end-to-end access to many properties, there will probably be several thousand lines of code by the end. None of this code is complicated, it just feels wrong.

Is this an inevitable consequence of the pattern?

Should I look at several ViewModels in this case? Perhaps one for the model class.

How did people handle non-trivial examples in the real world (as opposed to another demo)?

thank

BTW: WPF / Prism / C # / MVVM environment

+3
source share
3 answers

A bloated ViewModel is often a sign of a bloated view, maybe it can be divided into subviews?

Personally, I often find that most of the code in ViewModels is often code table code so that the view can know that some property has been updated (INotifyPropertyChanged). Take a look at Ayende's approach to solve this kind of swelling:

http://ayende.com/Blog/archive/2009/08/08/an-easier-way-to-manage-inotifypropertytyed.aspx

0
source

ViewModel . , , ViewModels... . Messenger Josh Smith MVVM Foundation.

, , ViewModel, . , - .

+1

ViewModel ?

Like any other class, you should be able to extract code for smaller collaborators, and then use delegation. Communication between virtual machines can be through calls to commands / events / methods. The VM must treat the other view or higher-level VM as one and the same (another client).

0
source

Source: https://habr.com/ru/post/1732806/


All Articles