Search code examples
c#wpfmvvminversion-of-controlunity-container

Accessing Unity Container from View Model


I am trying to use Unity Container in a small WPF-based project. In order to resolve dependencies when my ViewModels create other ViewModels, I need a reference to the container (which is initiated in App_OnStartup). What is the best way to achieve this?


Solution

  • If things are properly set up - ideally injecting IUnityContainer object in view model constructor should give you reference to all ViewModels as it will get resolved by unity.