title: Accessing unity container in view model class
body: <p>I have a shell which looks like toolbar and defines my main region (a wrap panel).  What I need to do is be able to add widgets to the shell and when a widget is clicked, a new window (view) is opened.  Below is what I have so far:</p>
  
  <p>I created a module class which adds a view to the main region:</p>
  
  <pre><code>public class MyModule : IModule
  {
    protected IUnityContainer Container { get; private set; }
  
    public MyModule(IUnityContainer container)
    {
      Container = container.CreateChildContainer();
    }
  
    public void Initialize()
    {
      var regionManager = Container.Resolve&lt;IRegionManager&gt;();
      MyModuleView myModuleView = new MyModuleView();
      regionManager.Regions["MainRegion"].Add(myModuleView);
    }
  }
  </code></pre>
  
  <p>Here is the content of MyModuleView:</p>
  
  <pre><code>  &lt;Grid&gt;
      &lt;Grid.DataContext&gt;
        &lt;vm:MyModuleVM/&gt;
      &lt;/Grid.DataContext&gt;
      &lt;Button Content="My Module" Foreground="White" FontWeight="Bold" Command="{Binding Path=LaunchCommand}"&gt;
      &lt;/Button&gt;
    &lt;/Grid&gt;
  </code></pre>
  
  <p>The view model, MyModuleVM:</p>
  
  <pre><code>  class MyModuleVM : ObservableObject
    {
      protected IUnityContainer Container { get; private set; }
  
      public MyModuleVM()
      {
      }
  
      RelayCommand _launchCommand;
      public ICommand LaunchCommand
      {
        get
        {
          if (_launchCommand == null)
          {
            _launchCommand = new RelayCommand(() =&gt; this.LaunchTestView(),
                () =&gt; this.CanLaunchTestView());
          }
          return _launchCommand;
        }
      }
  
      private void LaunchTestView()
      {
        TestView view = new TestView();
        view.Title = "Test View";
        var regionManager = Container.Resolve&lt;IRegionManager&gt;();
        regionManager.Regions["MyWindowRegion"].Add(view);
      }
  
      private bool CanLaunchTestView()
      {
          return true;
      }
    }
  </code></pre>
  
  <p>So my plan was as follows:</p>
  
  <ul>
  <li><p>Create the class that implements
  IModule (MyModule) and have it load a
  view (MyModuleView) into the shell
  when initialized</p></li>
  <li><p>Create a view model for the module
  (MyModuleVM) and set it as the
  DataContext of the view displayed in
  the shell</p></li>
  <li><p>MyModuleVM contains a command that a
  button in MyModuleView binds to. 
  When the button is clicked the
  command is triggered</p></li>
  <li><p>Now, here is where I am stuck.  Using
  a WindowRegionAdapter (an adapter
  that helps to create views in
  separate windows) I wanted to create
  and display a new view.  As seen in
  MyModuleVM, LaunchTestView needs
  access to the container in order to
  add the view to a region.  How am I
  supposed to get to the container?</p></li>
  </ul>
  
  <p>Besides my specific question about accessing the container, how is my overall strategy of adding "widgets" to a toolbar shell and launching
  views when they are clicked?  Am I comlpetely off track here when it comes to MVVM with Prism?</p>
  
  <p>Thanks guys.</p>