title: Using Unity.Mvc3 with HierarchicalLifetimeManager and Unit Of Work pattern no longer Lazy Loading
body: <p>First, my UoW inherits from DbContext.</p>
  
  <p>I moved over to using Unity.Mvc3 and added this line to my registrations:</p>
  
  <pre><code>Container.RegisterType&lt;IUnitOfWork, UnitOfWork&gt;(new HierarchicalLifetimeManager());
  </code></pre>
  
  <p>Once i moved to this, my lazy loading for Entity Framework has seemed to stop working. Here is an example:</p>
  
  <pre><code>public class Process
  {
       public Guid Id {get;set;}
       public virtual Guid? StatusId {get;set;} //this is the FK EF uses.
       public virtual Status Status {get;set;}
  }
  
  public class Status
  {
       public Guid ID {get;set;}
       public Name {get;set;}
  }
  
  //DTOs
  public class ProcessDto
  {
       public Guid Id {get;set;}
       public Guid? StatusId {get;set;} //this is the FK EF uses.
       public StatusDto Status {get;set;}
  }
  
  public class StatusDto
  {
       public Guid ID {get;set;}
       public Name {get;set;}
  }
  </code></pre>
  
  <p>The Satuses are loaded in the context before we call the Cre</p>
  
  <pre><code>//Process Service
      public ProcessDto Create(ProcessDto dto)
      {
         var processEntity = new Process(){StatusId = dto.StatusId}
         processRepository.Add(processEntity)
         unitOfWork.Commit()
         //at this point, before using Unity.Mvc3 the Status would be proxied into the   processEntity. Moving to Unity.Mvc3 it is like Lazy Loading stopped working.
         return Mapper.Map&lt;Process,ProcessDto&gt;(processEntity);
      }
  </code></pre>
  
  <p>Stepping through the code the request is not terminated until after the Create call. Not sure if anyone has run into something similar.</p>