title: Web Service nHibernate SessionFactory issue
body: <p>I have a C# .Net Web Service.  I am calling a dll (C# .Net) that uses nHibernate to connect to my database.  When I call the dll, it executes a query to the db and loads the parent Object "Task".  However, when the dll tries to access the child objects "Task.SubTasks", it throws the following error:</p>
  
  <pre><code>NHibernate.HibernateException failed to lazily initialize a collection of role:  SubTasks no session or session was closed
  </code></pre>
  
  <p>I'm new to nHibernate so not sure what piece of code I'm missing.  </p>
  
  <p>Do I need to start a Factory session in my web service before calling the dll?  If so, how do I do that?</p>
  
  <p>EDIT:  Added the web service code and the CreateContainer() method code.  This code gets called just prior to calling the dll</p>
  
  <pre><code>    [WebMethod]
      public byte[] GetTaskSubtask (string subtaskId)
      {
          var container = CreateContainer(windsorPath);
  
          IoC.Initialize(container);
          //DLL CALL
          byte[] theDoc = CommonExport.GetSubtaskDocument(subtaskId);
  
          return theDoc;
  
      }
  
  /// &lt;summary&gt;
  /// Register the IoC container.
  /// &lt;/summary&gt;
  /// &lt;param name="aWindsorConfig"&gt;The path to the windsor configuration 
  /// file.&lt;/param&gt;
  /// &lt;returns&gt;An initialized container.&lt;/returns&gt;
  protected override IWindsorContainer CreateContainer(
     string aWindsorConfig)
  {
      //This method is a workaround.  This method should not be overridden.  
      //This method is overridden because the CreateContainer(string) method 
      //in UnitOfWorkApplication instantiates a RhinoContainer instance that 
      //has a dependency on Binsor.  At the time of writing this the Mammoth 
      //application did not have the libraries needed to resolve the Binsor 
      //dependency.
  
      IWindsorContainer container = new RhinoContainer();
  
      container.Register(
         Component.For&lt;IUnitOfWorkFactory&gt;().ImplementedBy
            &lt;NHibernateUnitOfWorkFactory&gt;());
      return container;
  }
  </code></pre>
  
  <p>EDIT:  Adding DLL code and repository code...</p>
  
  <p>DLL Code</p>
  
  <pre><code>public static byte[] GetSubtaskDocument(string subtaskId)
  {
      BOESubtask task = taskRepo.FindBOESubtaskById(Guid.Parse(subtaskId));
  
      foreach(subtask st in task.Subtasks) &lt;--this is the line that throws the error
      {
      //do some work
      }
  
  
  }
  </code></pre>
  
  <p>Repository for task</p>
  
  <pre><code>/// &lt;summary&gt;
  /// Queries the database for the Subtasks whose ID matches the 
  /// passed in ID.
  /// &lt;/summary&gt;
  /// &lt;param name="aTaskId"&gt;The ID to find matching Subtasks 
  /// for.&lt;/param&gt;
  /// &lt;returns&gt;The Subtasks whose ID matches the passed in 
  /// ID (or null).&lt;/returns&gt;
  public Task FindTaskById(Guid aTaskId)
  { 
      var task = new Task();
      using (UnitOfWork.Start())
      {
          task =  FindOne(DetachedCriteria.For&lt;Task&gt;()
                      .Add(Restrictions.Eq("Id", aTaskId)));
          UnitOfWork.Current.Flush();
      }
      return task;
  }
  </code></pre>
  
  <p>Repository for subtask</p>
  
  <pre><code>/// &lt;summary&gt;
  /// Queries the database for the Subtasks whose ID matches the 
  /// passed in ID.
  /// &lt;/summary&gt;
  /// &lt;param name="aBOESubtaskId"&gt;The ID to find matching Subtasks 
  /// for.&lt;/param&gt;
  /// &lt;returns&gt;The Subtasks whose ID matches the passed in 
  /// ID (or null).&lt;/returns&gt;
  public Subtask FindBOESubtaskById(Guid aSubtaskId)
  { 
      var subtask = new Subtask();
      using (UnitOfWork.Start())
      {
          subtask =  FindOne(DetachedCriteria.For&lt;Subtask&gt;()
                      .Add(Restrictions.Eq("Id", aSubtaskId)));
          UnitOfWork.Current.Flush();
      }
      return subtask;
  }
  </code></pre>