title: ASP.NET Core HttpContext is null outside controller in case of Batch request
body: <p>In my ASP.NET Core OData service, when we make a batch request and try to access <code>HttpContext</code> outside the controller, it is null. In the case of not batch request <code>HttpContext</code> is populated correctly.</p>
  
  <p>I am using <code>IHttpContextAccessor</code> to get the <code>httpContext</code>:</p>
  
  <pre><code>public static class AspnetcoreHttpContext
  {
      public static IHttpContextAccessor contextAccessor;
  
      public static void SetContextAccessor(IHttpContextAccessor accessor)
      {
          contextAccessor = accessor;
      }
  
      /// &lt;summary&gt;
      /// Gets the current HTTP Context. This may be null!!!
      /// &lt;/summary&gt;
      public static HttpContext Current
      {
              get
              {
                  return contextAccessor?.HttpContext;
              }
      }
  }
  </code></pre>
  
  <p>In starup I have configured batch as below;</p>
  
  <pre><code>app.UseODataBatching();
  app.UseMvc(routeBuilder =&gt;
              {
                  var conventions = ODataRoutingConventions.CreateDefault();
                  ODataBatchHandler odataBatchHandler = new CustomODataBatchHandler();
                  ApiVersion version = new ApiVersion(1, 0);
                  string routeName = string.Format("odata-bypath{0}", version.MajorVersion.Value);
                  routeBuilder.MapVersionedODataRoute(routeName, "odata/v{version:apiVersion}",
                      EdmModel, version, new DefaultODataPathHandler(), conventions, batchHandler: odataBatchHandler);
              });
  </code></pre>
  
  <p>Any pointers? please suggest.</p>