Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Health Checks - Register path/options with dependency injection #18153

Open
jcoutch opened this issue Jan 6, 2020 · 2 comments
Open

Health Checks - Register path/options with dependency injection #18153

jcoutch opened this issue Jan 6, 2020 · 2 comments
Labels
affected-very-few This issue impacts very few customers area-healthchecks Includes: Healthchecks (some bugs also in Extensions repo) enhancement This issue represents an ask for new feature or an enhancement to an existing one severity-minor This label is used by an internal tool
Milestone

Comments

@jcoutch
Copy link

jcoutch commented Jan 6, 2020

Is your feature request related to a problem? Please describe.

This feature would directly support development efforts on:
domaindrivendev/Swashbuckle.AspNetCore#1058

When adding health checks using IApplicationBuilder.UseHealthChecks, the values of path and HealthCheckOptions are only used to map HealthCheckMiddleware. After the middleware is registered, there is no way to retrieve this information at runtime.

Describe the solution you'd like

To have HealthCheckApplicationBuilderExtensions.cs refactored in a non-breaking way so that the path and HealthCheckOptions information is accessible at runtime (preferably via dependency injection).

@Pilchie Pilchie added the area-healthchecks Includes: Healthchecks (some bugs also in Extensions repo) label Jan 7, 2020
@pranavkm pranavkm added this to the Backlog milestone Aug 13, 2020
@ghost
Copy link

ghost commented Aug 13, 2020

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@pranavkm pranavkm added the enhancement This issue represents an ask for new feature or an enhancement to an existing one label Aug 13, 2020
@weichch
Copy link
Contributor

weichch commented Oct 3, 2020

I'm not sure about the path, but for HealthCheckOptions, I used a workaround in my project:

var options = new HealthCheckOptions
{
    Predicate = check => check.Tags.Contains("test")
};

// Set options directly to IOptionsMonitor<HealthCheckOptions>
app.ApplicationServices
    .GetRequiredService<IOptionsMonitorCache<HealthCheckOptions>>()
    .TryAdd("my-options", options);

app.UseHealthChecks("/health", options);

Then I can access the options using dependency injection:

public MyController(IOptionsMonitor<HealthCheckOptions> optionsMonitor)
{
    var healthCheckOptions = optionsMonitor.Get("my-options");
}

Note: this doesn't mean HealthCheckOptions can be configured using the options pattern, because by the time TryAdd is called, it is unlikely you will have HealthCheckOptions already created in the cache, and there is no solid way to determine if you have registered any configuration for HealthCheckOptions in ConfigureServices.

@mkArtakMSFT mkArtakMSFT added affected-very-few This issue impacts very few customers severity-minor This label is used by an internal tool labels Nov 6, 2020 — with ASP.NET Core Issue Ranking
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affected-very-few This issue impacts very few customers area-healthchecks Includes: Healthchecks (some bugs also in Extensions repo) enhancement This issue represents an ask for new feature or an enhancement to an existing one severity-minor This label is used by an internal tool
Projects
None yet
Development

No branches or pull requests

5 participants