title: How to use IHttpContextAccessor in static class to set cookies
body: <p>I am trying to create a generic <code>addReplaceCookie</code> method in a static class. The method would look something like this</p>
  
  <pre><code>public static void addReplaceCookie(string cookieName, string cookieValue)
  {
  
      if ((HttpContext.Current.Request.Cookies(cookieName) == null))
      {
          // add cookie
          HttpCookie s = new HttpCookie(cookieName);
          s.Value = cookieValue;
          s.Expires = DateTime.Now.AddDays(7);
          HttpContext.Current.Response.Cookies.Add(s);
      }
      else {
          // ensure cookie value is correct 
          HttpCookie existingSchoolCookie = HttpContext.Current.Request.Cookies(cookieName);
          existingSchoolCookie.Expires = DateTime.Now.AddDays(7);
          existingSchoolCookie.Value = cookieValue;
          HttpContext.Current.Response.Cookies.Set(existingSchoolCookie);
      }
  
  }
  </code></pre>
  
  <p>I know that in order to get the <code>HttpContext</code> in asp.net core you have to use the <code>IHttpContextAccessor</code>. But I cannot inject it into a static class.</p>
  
  <p>Is there another way to get access to it?</p>
  
  <p>I am using rc1-final.</p>