aspnet / Diagnostics

[Archived] Diagnostics middleware for reporting info and handling exceptions and errors in ASP.NET Core, and diagnosing Entity Framework Core migrations errors. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
213 stars 111 forks source link

Did something change when registering health checks in preview3? #526

Closed ThomasArdal closed 5 years ago

ThomasArdal commented 5 years ago

In preview1, I could register health checks like this:

services.AddHealthChecks();
services.AddSingleton<IHealthCheck, MyHealthCheck>();

In preview3, my health check is no longer created and executed when requesting the health endpoint. Did something change?

mkArtakMSFT commented 5 years ago

Thanks for contacting us, @ThomasArdal. @rynowak, all yours to answer.

rynowak commented 5 years ago

Yes. We don't register the health checks directly in DI anymore. This turned out to be too limiting in a variety of ways.

Use services.AddHealthChecks().AddCheck<MyHealthCheck>("myname") if you don't care about lifetimes

or if you do want to enforce a singleton lifetime:

services.AddHealthChecks().AddCheck<MyHealthCheck>("myname");
services.AddSingleton<MyHealthCheck>();