Introducing ASP.NET HealthChecks.Extensions - Conditional Health Checks
ASP.NET Core offers the Health Checks Middleware , in order to check the health state of your .NET Core API. However is not always desirable to run all the registered Health Checks in every context. For example, in environments like the development one, some dependencies might not be available. Other dependencies might be used later during the application lifetime, maybe when their configuration is finished, or after a feature flag is enabled. Would be nice to decide when to run a health check. One possible way is to write the condition in the Startup class, as bellow: The Redis health check is added only when the configuration setting has the expected value. If the configuration is changed during the application lifetime, then the only way to re-add the Redis health check is by restarting the API, in order to call again the ConfigureServices method. Another good reason to switch on or off a health check is when a feature uses one or maybe more dependencies. If that fe...