title: How/Where to instantiate model objects in MVVM using PRISM and Unity
body: <p>I try to implement my first application using PRISM and UNITY.
  So i try to split my application in several modules.</p>
  
  <p>In my modules i have the related view as well as the view model.</p>
  
  <p>Currently i instantiate my viewmodel and set the datacontext of my view in the views code behind:</p>
  
  <pre><code>public partial class View : UserControl
  {
      public View(IViewModel vm)
      {
          InitializeComponent();
          this.DataContext = vm;
      }
  }
  </code></pre>
  
  <p>My model is instantiated using the unity-container in my view-models ctor.</p>
  
  <pre><code>public ViewModel(IEventAggregator eventAggregator, IUnityContainer container)
  {
      _eventAggregator = eventAggregator;
  
      _model = container.Resolve&lt;Model&gt;();
      this._model.PropertyChanged += new PropertyChangedEventHandler(OnModelPropertyChanged);
  }
  </code></pre>
  
  <p>Before i used the unity container i injected the models by dependency injection via the ViewModels constructor.</p>
  
  <p>But this seems not to work. I tried it in the following way:</p>
  
  <pre><code>public ViewModel(IEventAggregator eventAggregator, Model model)
  {
      _eventAggregator = eventAggregator;
      _model = model
      this._model.PropertyChanged += new PropertyChangedEventHandler(OnModelPropertyChanged);
  }
  </code></pre>
  
  <p>This implementation gives me an exception and i also couldn't find out how to setup the container so that the model injection works in the way i tried.</p>
  
  <p>What i would like to do is to instantiate my models in the module class. And from there i would like to inject it to my viewmodels. </p>
  
  <p>So my questions are:</p>
  
  <ol>
  <li>Is the way i do it currently correct?</li>
  <li>Is there a way to instantiate the models in the module class and inject them to the viewmodels, if so how and are there any examples on the web?</li>
  </ol>