title: Check whether class instance already exists
body: <p>I want to know whether we can write a code explicitly so as to know whether the instance of the class is already available or not and if the instance is available we could dispose it and then the new instance of the class can be created
  I am doing a project in WPF and Prism with very limited knowledge in it.
  Any help would be appreciated.</p>
  
  <pre><code>public class BillingSectionModule : IModule
  {
      private IRegionManager _regionManager;
      private IUnityContainer _unityContainer;
  
      public BillingSectionModule(IRegionManager regionManager, IUnityContainer unityContainer)
      {
          this._regionManager = regionManager;
          this._unityContainer = unityContainer;
      }
  
      #region IModule Members
  
      public void Initialize()
      {
          _unityContainer.RegisterType&lt;IBillingSectionViewModel, BillingSectionViewModel&gt;();
          _unityContainer.RegisterType&lt;IBillingSectionView, BillingSectionView&gt;();
          _unityContainer.RegisterType&lt;IBillingSectionAdvanceBillingViewModel, BillingSectionAdvanceBillingViewModel&gt;();
          _unityContainer.RegisterType&lt;IBillingSectionAdvanceBillingView, BillingSectionAdvanceBillingView&gt;();
          _regionManager.RegisterViewWithRegion(RegionNames.BillingOptionRegion, typeof(IBillingSectionView));
      }
  
      #endregion
  }
  </code></pre>
  
  <p>This is the module class i Ve written...
  As you can see there is two views associated with a single module.
  So when ever </p>
  
  <pre><code>public void ChangeToAdvanceRegion(IRegionManager regionManager, IUnityContainer unityContainer)
  {
  
  
      //change Billing Area
      var BillingAreaview = ServiceLocator.Current.GetInstance&lt;IBillingSectionAdvanceView&gt;();
      if (!regionManager.Regions[RegionNames.BillingOptionRegion].Views.Contains(BillingAreaview))
          regionManager.Regions[RegionNames.BillingOptionRegion].Add(BillingAreaview);
      regionManager.Regions[RegionNames.BillingOptionRegion].Activate(BillingAreaview);
  
  
      //reset the values
      _eventAggregator.GetEvent&lt;NewItemOrderEvent&gt;().Publish("CHANGEADVANCEITEMFROMREGION");
  }
  
  public void ChangeToNewOrderRegion(IRegionManager regionManager, IUnityContainer unityContainer)
  {
  
      //change Billing Area
      var BillingAreaview = ServiceLocator.Current.GetInstance&lt;IBillingSectionView&gt;();
      if (!regionManager.Regions[RegionNames.BillingOptionRegion].Views.Contains(BillingAreaview))
          regionManager.Regions[RegionNames.BillingOptionRegion].Add(BillingAreaview);
      regionManager.Regions[RegionNames.BillingOptionRegion].Activate(BillingAreaview);
  
  
      //reset the values
      _eventAggregator.GetEvent&lt;NewItemOrderEvent&gt;().Publish("CHANGENEWITEMFROMREGION");
  }
  </code></pre>
  
  <p>So when ever i call above functin first and then the second one.. the previously created instance of the view model is not been disposed.. but a new one is created...
  so when i call the nth time.. the function inside the view model is executed n tyms. creating load issues in the application....</p>