title: How to use session and call from class asp.net mvc 6
body: <p>I am trying to use session in asp.net mvc 6 from calling class inside of Iactionresult.</p>
  
  <p>I have class as "<strong>SessionTool</strong> as below"</p>
  
  <p>SessionTool class:</p>
  
  <pre><code>public class SessionTool
  {
          private readonly IHttpContextAccessor HttpContextAccessor;
  
          public SessionTool(IHttpContextAccessor httpContextAccessor)
          {
              HttpContextAccessor = httpContextAccessor;
          }
  
          public void SetSession(string key, string value)
          {
              HttpContextAccessor.HttpContext.Session.SetString(key, value);
          }
  
          public string GetSession(string key)
          {
              return HttpContextAccessor.HttpContext.Session.GetString(key);
          }
   }
  </code></pre>
  
  <p>I have <strong>HomeController</strong> as below.</p>
  
  <pre><code>public class HomeController : Controller
  {
  
          [HttpGet]
          public IActionResult Login() 
          {
  
  
          SessionTool sessionTool = new SessionTool(IHttpContextAccessor);
  
  
          }
  }
  </code></pre>
  
  <p><strong>Question:</strong></p>
  
  <p>If i try to call SessionTools class as below IHttpContextAccessor displays warning as IHttpContextAccessor is a type , which is not valid in the given context.</p>
  
  <pre><code>SessionTool sessionTool = new SessionTool(IHttpContextAccessor);
  </code></pre>
  
  <p>I am new in asp.net mvc 6 and i am not sure how can i set new instance of IHttpContextAccessor to session tool than use session classes ?</p>
  
  <p>Any help will be appreciated.
  Thanks</p>