I am following MVVM pattern and have my Views in Solution.UserInterface assembly and ViewModels in Solution.BusinessLogic assembly. As far as I know, ViewModels should know nothing about Views and Views should hold reference to ViewModels. However, what if I would like to open my custom View from ViewModel from Solution.BusinessLogic? (for example, Insert new item window). I can't because that would mean to add a reference to Views and therefore cause a circular dependency. How to solve this issue?
1 Answers
I think you are mixing up a few things here. MVVM has three parts: The Model, the View and the ViewModel. The View represents your data and is bound to your ViewModel. Both of these usually exist in the same User Interface assembly like Solution.UserInterface. In a View-first approach the ViewModel knows nothing about its associated View(s) - this is correct. But it can easily work with other Views like showing a new window that is bound to another ViewModel.
The Model is the place where your business logic should reside. This could very well be in another assembly. The ViewModel holds a reference to the business object and possibly converts it to another format to let the associated View(s) show it in a readable format.
Please also refer to this question for clarification: Should I implement business logic on a Model or a ViewModel