title: Loading a prism module view from the shell, using MEF
body: <p>I have a shell project which is loading modules in my bootstrapper into a tab control in my shell's main view.</p>
  
  <p>I have just implemented a close button on my tab items which now poses the question of how do I reload module views from the shell?</p>
  
  <p>Tried using </p>
  
  <pre><code>moduleManager.LoadModule("ModuleA");
  </code></pre>
  
  <p>but this only works when the module is first loaded. When I call the above it loads and initializes the module, displaying the view. If I then close the view again, the 2nd time I try this it doesn't reshow the view (I'm guessing it doesn't reinitialize the module as it's already loaded).</p>
  
  <p>So, I though I thought about using something along the lines of the following in my shell:</p>
  
  <pre><code>var moduleAView = ServiceLocator.Current.GetInstance&lt;ModuleAView&gt;();
  regionManager.Regions["TabRegion"].Add(ModuleAView);
  regionManager.Regions["TabRegion"].Activate(ModuleAView);
  </code></pre>
  
  <p>Trouble with this approach is how does my shell know about the type ModuleAView in line 1? I don't have a reference to module A and don't want to add one. I thought about a common interface that ModuleAView would implement, that could be shared amongst the module and the shell but I got a composition error when trying to use the ServiceLocator.GetInstance approach as above.</p>
  
  <p>Many thanks for your help.</p>
  
  <p>PS
  This is the module A module code I tried.</p>
  
  <pre><code>[ModuleExport(typeof(ModuleA), InitializationMode = InitializationMode.OnDemand)]
  [Module(ModuleName="ModuleA")]
  public class ModuleA : IModule
  {
      private IRegionManager _regionManager;
  
      [ImportingConstructor]
      public ModuleA(IRegionManager regionManager)
      {
          this._regionManager = regionManager;
      }
  
      public void Initialize()
      {
          // add the search view to the region manager.
          this._regionManager.RegisterViewWithRegion("TabRegion", typeof(Views.ModuleAView));
      }
  }
  </code></pre>