title: Accessing Httpcontext outside controller in .net core
body: <p>I can't access Session variables outside controllers, there are over 200 examples where they advise you to add <code>;</code></p>
  <p><code>services.TryAddSingleton&lt;IHttpContextAccessor, HttpContextAccessor&gt;();</code></p>
  <pre><code>services.AddHttpContextAccessor();
  </code></pre>
  <p>and use</p>
  <pre><code>public class DummyReference
  {
          private IHttpContextAccessor _httpContextAccessor;
          public DummyReference(IHttpContextAccessor httpContextAccessor)
          {
              _httpContextAccessor = httpContextAccessor;
          }
          public void DoSomething()
          {
              // access _httpcontextaccessor to reach sessions variables
          }
  }
  </code></pre>
  <p>But, no-one mentions how to call this class from my controller. How can I reach that class?</p>
  <p>If changed it to static then I need bypass construct. If I create it I need httpcontextaccessor for construct.</p>
  <p>For who wants learn more why I approached like that, I want to write class include methods like encrypt, decrypt database tables RowIDs for masking in VIEW with value+sessionvariable to ensure its not modified.</p>
  <p>Also I want DummyReference to be static, that way I can easily reach DummyReference.EncryptValue or DecryptValue.</p>