I have quite a large number of parent-detail ViewModels in my MVVM application. Something like this:
SchoolsViewModel
+- SchoolViewModel
+- LessonViewModel
+- PupilsViewModel
+- PupilViewModel
+- TeacherViewModel
+- PupilsViewModel
+- PupilViewModel
+- LessonsViewModel
+- TeachersViewModel
And so on...
In addition, a single view model can appear in more than one place, depending on whether the user is browsing by lesson or pupil, etc.
Each child view model is created by the parent view model, and so many of the view models needs to have the dependencies of the child view model passed in. For example the constructor for SchoolsViewModel might 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 in all the required arguments to the view model. However, because in this case my application will usually only be creating the SchoolsViewModel this is of limited use.
My first question is, in this case, would you make SchoolsViewModel pass in each dependency to each child view model, or would you make each view model use ObjectFactory.GetInstance() to create the child view models? Perhaps through a factory class to abstract out the dependency on the DI framework?
There is another question relating to this: http://stackoverflow.com/questions/1136052/mvvm-locating-other-viewmodels
EDIT: I've opened a bounty on this as I'd like more opinions.