title: How to inject dependencies inside an ASP.NET Core Health Check
body: <p>I'm trying to use the new <a href="https://blogs.msdn.microsoft.com/webdev/2018/08/22/asp-net-core-2-2-0-preview1-healthcheck/" rel="noreferrer">ASP.NET Code 2.2 Healthchecks</a> feature.</p>
  
  <p>In this <a href="https://blogs.msdn.microsoft.com/webdev/2018/08/22/asp-net-core-2-2-0-preview1-healthcheck/" rel="noreferrer">link</a> on the .net blog, it shows an example:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public void ConfigureServices(IServiceCollection services)
  {
      //...
      services
          .AddHealthChecks()
          .AddCheck(new SqlConnectionHealthCheck("MyDatabase", Configuration["ConnectionStrings:DefaultConnection"]));
      //...
  }
  
  public void Configure(IApplicationBuilder app)
  {
      app.UseHealthChecks("/healthz");
  }
  </code></pre>
  
  <p>I can add custom checks that implement the <code>Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheck</code> interface. But since I need to provide to the <code>AddCheck</code> method an instance instead of a type, and it needs to run inside the <code>ConfigureServices</code> method, I can't inject any dependency in my custom checker.</p>
  
  <p>Is there any way to workaround this?</p>