diff --git a/src/Diagnostics.HealthChecks/HealthCheckHttpClientServiceCollectionExtensions.cs b/src/Diagnostics.HealthChecks/HealthCheckHttpClientServiceCollectionExtensions.cs new file mode 100644 index 00000000..a6c8195f --- /dev/null +++ b/src/Diagnostics.HealthChecks/HealthCheckHttpClientServiceCollectionExtensions.cs @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. + +using System.Net.Http; +using Microsoft.Extensions.DependencyInjection; + +namespace Microsoft.Omex.Extensions.Diagnostics.HealthChecks; + +/// +/// A collection of extension methods to define for Health Checks +/// in the DI. +/// +public static class HealthCheckHttpClientServiceCollectionExtensions +{ + /// + /// Defines a in the DI designed for Health Checks. + /// The main difference is that these clients in development will ignore SSL errors. + /// This is an acceptable compromise considering that the health checks are executed in the same machine + /// as the Service Fabric service itself, and that each client will be specifically used for the + /// health checks, as the name parameter in input is mandatory. + /// Every other uses of this extension methods apart from health checks should be avoided. + /// + /// The services. + /// The logical name of the to configure. + /// The . + public static IHttpClientBuilder AddHealthCheckHttpClient(this IServiceCollection services, string name) => + services.AddHttpClient(name) + .ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler + { + ServerCertificateCustomValidationCallback = (_, _, _, _) => true + }); +}