title: is StructureMap HttpContextScoped necessary?
body: <p>I saw a code as below in a tutorial of <code>EF code first</code> , <code>MVC</code> and <code>StructureMap</code> to create a <code>Context Per Request</code> pattern:</p>
  
  <pre><code>    protected void Application_Start()
      {
          ...
  
          initStructureMap();
  
      }
  
      private static void initStructureMap()
      {
  
          ObjectFactory.Initialize(x =&gt;
          {
              x.For&lt;IUnitOfWork&gt;().HttpContextScoped().Use(() =&gt; new Context());
              x.For&lt;IFirstEntity&gt;().Use&lt;FirstEntity&gt;();
              x.For&lt;ISecondEntity&gt;().Use&lt;SecondEntity&gt;();
              x.For&lt;IThirdEntity&gt;().Use&lt;ThirdEntity&gt;();
          });
  
          ControllerBuilder.Current.SetControllerFactory(new StructureMapControllerFactory());
      }
  
      protected void Application_EndRequest(object sender, EventArgs e)
      {
          ObjectFactory.ReleaseAndDisposeAllHttpScopedObjects();
      }
  
  
  public class StructureMapControllerFactory : DefaultControllerFactory
  {
      protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
      {
          return ObjectFactory.GetInstance(controllerType) as Controller;
      }
  }
  </code></pre>
  
  <p><code>FirstEntity</code> ,<code>SecondEntity</code> and ... all need <code>IunitOfWork</code> in their constructor .</p>
  
  <p>as you can see it just uses <code>HttpContextScoped()</code> for the <code>Context</code> not others and in the <code>EndRequest</code> event it calls <code>ReleaseAndDisposeAllHttpScopedObjects()</code> . </p>
  
  <p>1- is this a correct approach ?</p>
  
  <p>2- shall I use HttpContextScoped() for all other <code>Service layer Interfaces</code> or not just for <code>IUnitOfWork</code>? e.g</p>
  
  <pre><code>x.For&lt;IFirstEntity&gt;().Use&lt;FirstEntity&gt;();
  </code></pre>
  
  <p>or</p>
  
  <pre><code>x.For&lt;IFirstEntity&gt;().HttpContextScoped().Use(() =&gt; new FirstEntity());
  </code></pre>
  
  <p>3- <code>ReleaseAndDisposeAllHttpScopedObjects()</code> disposes all instances or just disposes <code>Context</code> ?</p>