Make it optional to register HealthCheckPublisherHostedService when using AddHealthChecks
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Is your feature request related to a problem? Please describe.
I am trying to use the `Microsoft.Extensions.Diagnostics.HealthChecks` library in a project but I don't want to register the default `HealthCheckPublisherHostedService` which is automatically registered when the `AddHealthChecks` extension method is used. I still would like to use the `DefaultHealthCheckService` and the `HealthChecksBuilder` which unfortunately are all marked as `internal` which means that I would have to implement them again in my code.
What I want to do is running my health checks manually with the help of the `DefaultHealthCheckService` inside of an [Orleans](https://github.com/dotnet/orleans) cluster. The reason why I don't want to register the `HealthCheckPublisherHostedService` is that it would execute and publish all health checks on each node periodically which is unnecessary.
### Describe the solution you'd like
I would like a method similar to `AddHealthChecks` or a parameter for `AddHealthChecks` to control if the `HealthCheckPublisherHostedService` gets registered or not.
### Additional context
The corresponding code which registers the `HealthCheckPublisherHostedService` can be found here:
https://github.com/dotnet/aspnetcore/blob/7a2b8205fbc9a241c7ee9da86261de3faccd379c/src/HealthChecks/HealthChecks/src/DependencyInjection/HealthCheckServiceCollectionExtensions.cs#L29
Contributor guide
Assessment
This issue has not been assessed yet.