title: How to inject ISession into Repository correctly?
body: <p>Please correct me on the following scenario.  ( Question is at the end)</p>
  
  <p>(I asked a similar question that was un-organized and it was voted to close. So I have summarized the question here into a scope that can be replied with exact answers.)</p>
  
  <p>I am developing a web application with multiple layers using nhibernate as ORM. My layer structure is as follow</p>
  
  <ol>
  <li>Model Layer</li>
  <li>Repository Layer</li>
  <li>Services Layer</li>
  <li>UI Layer</li>
  </ol>
  
  <p>with the above layers, the classes and interfaces are placed as below.</p>
  
  <p><strong>ProductController.cs (UI Layer)</strong></p>
  
  <pre><code>public class ProductController : Controller
  {
      ProductServices _ProductServices;
      NHibernate.ISession _Session;
  
      public ProductController()
      {
          _Session = SessionManager.GetCurrentSession();
  
          _ProductServices = new ProductServices(
              new ProductRepository(), _Session);
      }
      // Cont..
   }
  </code></pre>
  
  <p><strong>ProductServices.cs (Service Layer)</strong></p>
  
  <pre><code>public class ProductServices : IProductServices
  {
      protected IProductRepository _ProductRepository;
      protected NHibernate.ISession _Session;
  
      public ProductServices(IProductRepository productRepository,
          NHibernate.ISession session)
      {
          _ProductRepository = productRepository;
          _Session = session;
          _ProductRepository.SetSession(_Session);
      }
  
      // cont...
  }
  </code></pre>
  
  <p><strong>ProductRepository.cs (Repository Layer)</strong></p>
  
  <pre><code>public class ProductRepository : IProductRepository
  {
      NHibernate.ISession _Session;
  
      public void SetSession(NHibernate.ISession session)
      {
          _Session = session;
      }
  
      public IEnumerable&lt;Product&gt; FindAll()
      {
          return _Session.CreateCriteria&lt;Product&gt;().List&lt;Product&gt;();
      }
  
      //cont..
  }
  </code></pre>
  
  <p>From the UI layer, I create the session as request per session and inject into service layer with the help of class constructor. Then set the session of repository with a help of a method. </p>
  
  <p>I am afraid if I pass the _Session directly to repository as constructor, I will not have the control over it under the service layer. Also there is a future extension plan for using a <strong>webservice</strong> layer.</p>
  
  <p>** Is there a way to ensure in each method of ProductRepository class that <code>_Session</code> is set already, without writing the piece of code <code>if(_Session==null)</code> in each and every method as it is repeating the same code.</p>
  
  <p>**  If the above pattern is wrong, Please show me a right way to achieve this goal.</p>