dotnet / dotnet/aspnetcore

Make it optional to register HealthCheckPublisherHostedService when using AddHealthChecks

Open
#29,896 5 comments 3 reactions 0 assignees View on GitHub
affected-few area-healthchecks enhancement severity-minor
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.