// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; namespace Microsoft.Extensions.Diagnostics.HealthChecks { /// /// Represent the registration information associated with an implementation. /// /// /// /// The health check registration is provided as a separate object so that application developers can customize /// how health check implementations are configured. /// /// /// The registration is provided to an implementation during execution through /// . This allows a health check implementation to access named /// options or perform other operations based on the registered name. /// /// public sealed class HealthCheckRegistration { private Func _factory; private string _name; /// /// Creates a new for an existing instance. /// /// The health check name. /// The instance. /// /// The that should be reported upon failure of the health check. If the provided value /// is null, then will be reported. /// /// A list of tags that can be used for filtering health checks. public HealthCheckRegistration(string name, IHealthCheck instance, HealthStatus? failureStatus, IEnumerable tags) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (instance == null) { throw new ArgumentNullException(nameof(instance)); } Name = name; FailureStatus = failureStatus ?? HealthStatus.Unhealthy; Tags = new HashSet(tags ?? Array.Empty(), StringComparer.OrdinalIgnoreCase); Factory = (_) => instance; } /// /// Creates a new for an existing instance. /// /// The health check name. /// A delegate used to create the instance. /// /// The that should be reported when the health check reports a failure. If the provided value /// is null, then will be reported. /// /// A list of tags that can be used for filtering health checks. public HealthCheckRegistration( string name, Func factory, HealthStatus? failureStatus, IEnumerable tags) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (factory == null) { throw new ArgumentNullException(nameof(factory)); } Name = name; FailureStatus = failureStatus ?? HealthStatus.Unhealthy; Tags = new HashSet(tags ?? Array.Empty(), StringComparer.OrdinalIgnoreCase); Factory = factory; } /// /// Gets or sets a delegate used to create the instance. /// public Func Factory { get => _factory; set { if (value == null) { throw new ArgumentNullException(nameof(value)); } _factory = value; } } /// /// Gets or sets the that should be reported upon failure of the health check. /// public HealthStatus FailureStatus { get; set; } /// /// Gets or sets the health check name. /// public string Name { get => _name; set { if (value == null) { throw new ArgumentNullException(nameof(value)); } _name = value; } } /// /// Gets a list of tags that can be used for filtering health checks. /// public ISet Tags { get; } } }