I have a fairly large number of ViewModels with parent drilldown in my MVVM application. Something like that:
SchoolsViewModel +- SchoolViewModel +- LessonViewModel +- PupilsViewModel +- PupilViewModel +- TeacherViewModel +- PupilsViewModel +- PupilViewModel +- LessonsViewModel +- TeachersViewModel
And so on...
In addition, one viewing model can be displayed in more than one place, depending on whether the user is viewing a lesson or student, etc.
Each model of the child view is created by the model of the parent view, so many view models must have dependencies on the model of the child view. For example, the constructor for SchoolsViewModel could be:
SchoolsViewModel(ISchoolsRepository schoolsRepository, ILessonsRepository lessonsRepository, IPupilsRepository pupilsRepository, ITeachersRepository teachersRepository, ...)
Now, the usual way to make all this manageable is to use a DI framework such as StructureMap to pass all the necessary arguments to the view model. However, since in this case my application will usually only create SchoolsViewModel, this will be limited use.
My first question is: in this case, could you make the SchoolsViewModel transition in each dependency to each child view model, or would you use each ViewFactory.GetInstance () view model to create child view models? Perhaps through the factory class to abstract the dependency on the DI framework?
There is another question related to this: MVVM: searching for other ViewModels
EDIT: I discovered the generosity on this, as I would like more opinions.