title: Session Per ViewModel in Desktop Application with Repository
body: <p>I have been writing a WPF DESKTOP application using NHibernate, WPF, Prism and Unity Container but have a problem in terms of Session Management in Services / Repositories and how to do it cleanly through dependency injection using Unity.</p>
  
  <p>Having read <a href="http://msdn.microsoft.com/enus/magazine/ee819139.aspx" rel="nofollow noreferrer">Building A Desktop To Do-Application With NHibernate</a> I now have a Session Per ViewModel / Presenter. </p>
  
  <p>However, if I have several services on my viewmodel I have to pass the Session into each and every service which seems cumbersome and not quite right as I want to perform all data access through a repository.</p>
  
  <p>e.g </p>
  
  <pre><code>CustomerMaintenanceViewModel
  {
       service1.Session = SessionForThisPresenter;
       service2.Session = SessionForThisPresenter;
       service3.Session = SessionForThisPresenter;
       service1.GetAllSomething();
       service2.GetAllSomething();
       service3.GetAllSomething();
  }
  </code></pre>
  
  <p>Each service is essentially a facade over a repository and I would want each repository for this presenter to be involved in the same session without explicitly setting it.</p>
  
  <p>Any advice on how to handle this would be most appreciated as I am sure there is a solution quite close but I am not sure how to do it.</p>