title: Access the current HttpContext in ASP.NET Core with Custom
body: <p>I am writing code for following: <a href="https://stackoverflow.com/questions/31243068/access-the-current-httpcontext-in-asp-net-core">Access the current HttpContext in ASP.NET Core</a></p>
  
  <p>I am receiving error. How would I resolve this?
  Also, whats the code for Interface <code>IMyComponent</code>? Just want to be sure its correct.</p>
  
  <p><strong>Errors:</strong></p>
  
  <blockquote>
    <p>Type or namespace IMyComponent Cannot be found
    The Name 'KEY' does not exist in current context.</p>
  </blockquote>
  
  <pre><code>public class MyComponent : IMyComponent
  {
      private readonly IHttpContextAccessor _contextAccessor;
  
      public MyComponent(IHttpContextAccessor contextAccessor)
      {
          _contextAccessor = contextAccessor;
      }
  
      public string GetDataFromSession()
      {
          return _contextAccessor.HttpContext.Session.GetString(*KEY*);
      }
  }
  </code></pre>