microsoft/healthcare-shared-components

Public

mirrored from https://github.com/microsoft/healthcare-shared-componentsAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
main

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/Microsoft.Health.Api/Registration/HealthCheckRegistrationExtensions.cs

43lines · modecode

1// -------------------------------------------------------------------------------------------------
2// Copyright (c) Microsoft Corporation. All rights reserved.
3// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
4// -------------------------------------------------------------------------------------------------
5
6using System;
7using EnsureThat;
8using Microsoft.Extensions.DependencyInjection.Extensions;
9using Microsoft.Extensions.Diagnostics.HealthChecks;
10using Microsoft.Extensions.Options;
11using Microsoft.Health.Api.Features.HealthChecks;
12
13namespace Microsoft.Extensions.DependencyInjection;
14
15/// <summary>
16/// A collection of methods for configuring health checks.
17/// </summary>
18public static class HealthCheckRegistrationExtensions
19{
20 /// <summary>
21 /// Configures the global timeout for all health checks.
22 /// </summary>
23 /// <param name="services">The <see cref="IServiceCollection"/> containing the services.</param>
24 /// <param name="timeout">The global health check timeout.</param>
25 /// <returns>The <paramref name="services"/> for additional method invocations.</returns>
26 /// <exception cref="ArgumentNullException">
27 /// <paramref name="services"/> is <see langword="null"/>.
28 /// </exception>
29 /// <exception cref="ArgumentOutOfRangeException">
30 /// <paramref name="timeout"/> is negative.
31 /// </exception>
32 public static IServiceCollection ConfigureHealthCheckTimeout(this IServiceCollection services, TimeSpan timeout)
33 {
34 EnsureArg.IsNotNull(services, nameof(services));
35 EnsureArg.IsGte(timeout, TimeSpan.Zero, nameof(timeout));
36
37 services.TryAdd(
38 ServiceDescriptor.Transient<IPostConfigureOptions<HealthCheckServiceOptions>, HealthCheckTimeoutPostConfigure>(
39 p => new HealthCheckTimeoutPostConfigure(timeout)));
40
41 return services;
42 }
43}
44