title: Cannot use HttpContext.Session in asp.net core
body: <p>I've added <code>app.UseSession();</code> to my startup.Configure and <code>services.AddSession()</code> to my ConfigureServices.</p>
  <p>Now if I try to use Session like this:</p>
  <p><code>HttpContext.Session.SetString(&quot;Type&quot;, tableName);</code></p>
  <p>I get &quot;an object reference is required for the non-static field, method or property, 'HttpContext.Session'&quot;</p>
  <p>However, if I try to instantiate it like this:
  <code>HttpContext context = new HttpContext();</code></p>
  <p>it says: &quot;Cannot create an instance of the abstract class or interface 'HttpContext&quot;</p>
  <p>How can I access session?</p>
  <p><strong>IQuery.cs</strong></p>
  <pre><code>using Microsoft.AspNetCore.Http;
  using System;
  using System.Collections.Generic;
  using System.Data;
  using System.Data.SqlClient;
  using System.Linq;
  
  namespace AppName.Services
  {
      public interface IQuery
      {
          List&lt;Dictionary&lt;string, string&gt;&gt; GetListOfDatabases(string dbName);
      }
      public class InMemoryIquery : IQuery
      {
          public List&lt;Dictionary&lt;string, string&gt;&gt; GetListOfDatabases(string tableName)
          {
          if(tableName != null)
              {
                 HttpContext.Session.SetString(&quot;Type&quot;, tableName);
              }
          }
      }
  </code></pre>