title: Instantiate IUnitOfWork for each ViewModels in WPF/Prism app
body: <p>I have lots of repositories like this:</p>
  
  <pre><code>public class PersonRepository : IPersonRepository
  {
      private readonly IUnitOfWork _unitOfWork;
  
      public PersonRepository(IUnitOfWork instance)
      {
          _unitOfWork = instance;
      }
  
      //Remove, Get methods...
      public void Add(Person p)
      {
          _unitOfWork.Context.People.Add(p);
      }
  }
  </code></pre>
  
  <p>and Unit of work class like this:</p>
  
  <pre><code>public class UnitOfWork : IUnitOfWork, IDisposable
  {
      public UnitOfWork(){ }
  
      private readonly HezarehContext _context = new HezarehContext();
      public HezarehContext Context
      {
          get
          {
              return _context;
          }
      }
  
      public int Save()
      {
          return _context.SaveChanges();
      }
  
      public void Initialize()
      {
          Context.Database.Initialize(false);
      }
  
      #region IDisposable Members
  
      public void Dispose()
      {
          _context.Dispose();
      }
  
      #endregion
  }
  </code></pre>
  
  <p>Now i want each time my ViewModels gets resolved, a new <code>IUnitOfWork</code> instantiated. Most of my ViewModels are like this:</p>
  
  <pre><code>public class PeopleMainViewModel : NotificationObject
  {
      // both of repositories must have same instance of IUnitOfWork
      private readonly IPersonRepository _personRepository = ServiceLocator.Current.GetService&lt;IPersonRepository&gt;();
      private readonly ICategoryRepository _categoryRepository = ServiceLocator.Current.GetService&lt;ICategoryRepository&gt;();
  
      public PeopleMainViewModel()
      {
          InitializeView();
      }
  
      // add, edit, remove commands ...
  }
  </code></pre>
  
  <p>ViewModels always gets resolved using Unity Container like this:</p>
  
  <pre><code>Container.RegisterType&lt;IPersonRepository, PersonRepository&gt;();
  // resolve in InjectionProperty...
  Container.RegisterType&lt;Object, PeopleMainView&gt;("PeopleMainView", new InjectionProperty(PeopleMainView.DataContextProperty.Name, Container.Resolve&lt;PeopleMainViewModel&gt;();
  </code></pre>
  
  <p>And my question is, <strong>How</strong> and <strong>Where</strong> i Register my <code>ViewModel</code>s and <code>IUnitOfWork</code> to have <code>IUnitOfWork</code> instance for each of them?</p>