// 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 Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
namespace Microsoft.AspNetCore.Builder
{
///
/// extension methods for the .
///
public static class HealthCheckApplicationBuilderExtensions
{
///
/// Adds a middleware that provides health check status.
///
/// The .
/// The path on which to provide health check status.
/// A reference to the after the operation has completed.
///
/// The health check middleware will use default settings other than the provided .
///
public static IApplicationBuilder UseHealthChecks(this IApplicationBuilder app, PathString path)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
if (!path.HasValue)
{
throw new ArgumentException("A URL path must be provided", nameof(path));
}
return app.Map(path, b => b.UseMiddleware());
}
///
/// Adds a middleware that provides health check status.
///
/// The .
/// The path on which to provide health check status.
/// A used to configure the middleware.
/// A reference to the after the operation has completed.
public static IApplicationBuilder UseHealthChecks(this IApplicationBuilder app, PathString path, HealthCheckOptions options)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
if (!path.HasValue)
{
throw new ArgumentException("A URL path must be provided", nameof(path));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
return app.Map(path, b => b.UseMiddleware(Options.Create(options)));
}
}
}