title: Why is DbContext (ASP.NET) null in MyService?
body: <p>I use c#, ASP.NET Core, EF.</p>
  
  <p>I have Startup.cs:</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
          {
              services.AddDbContext&lt;AppDbContext&gt;(options =&gt;
                  options.UseSqlServer(
                      Configuration.GetConnectionString("DefaultConnection")));
              ...
          }
  </code></pre>
  
  <p>I have Controller:</p>
  
  <pre><code>public class HomeController : Controller
  {
          public AppDbContext _db;
  
          public HomeController(AppDbContext db)
          {
              _db = db;
          }
  
          public IActionResult Index()
          {
           // _db is NOT NULL           
           var d = _db.Users.FirstOrDefault();
          }
  }
  </code></pre>
  
  <p>I have class MyService.cs:</p>
  
  <pre><code>public class MyService
  {
          public static AppDbContext _db;
  
          public MyService(AppDbContext db)
          {
              _db = db;
          }
  
          public static void GetOtherValue()
          {   
               // _db is NULL           
               var d = _db.Users.FirstOrDefault();
          }
    }
  </code></pre>
  
  <p>HomeController works correctly: <strong>_db</strong> is not null. </p>
  
  <p>Why variable <strong>_db is null in MyService.cs</strong>? How to fix it?</p>
  
  <p><strong>UP:</strong></p>
  
  <pre><code>public class OtherController : Controller
  {
      ....
      MyService.GetOtherValue();
      ....
  }
  </code></pre>