I'm just starting to dig into the MVVM pattern for WPF but because I'm not a professional developer, I sometimes feel a little lost.
The main problem I have is deciding who should create whom: Let's say I have a database storing dogs and cats. I would then have a DatabaseManager which communicates with the database (Unit of Work!?), a DogRepository / CatRepository and the Dogs / Cats objects.
On the other side I have my MainWindow with which the user can open/close the database and which contains a Listbox for cats and one for dogs, so I need a MainWindowViewModel, CatsViewModel and DogsViewModel.
But how do I create these objects? In my application I create the MainWindow obviously. And then? Do I create a MainWindowViewModel and pass it to the MainWindow or does the MainWindow create its own MainWindowViewModel? How is the DatabaseManager created? By the MainWindowViewModel?
What about the CatsViewModel and the corresponding CatRepository? Does the MainWindowViewModel create the CatsViewModel which in turn creates a CatRepository? I'm really confused.