Ejemplo n.º 1
0
        /// <summary>
        ///     Adds App Metrics Helath services, configuration and middleware to the
        ///     <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" />.
        /// </summary>
        /// <param name="hostBuilder">The <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" />.</param>
        /// <returns>A reference to this instance after the operation has completed.</returns>
        /// <exception cref="ArgumentNullException">
        ///     <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" /> cannot be null
        /// </exception>
        public static IWebHostBuilder UseHealthEndpoints(this IWebHostBuilder hostBuilder)
        {
            hostBuilder.ConfigureHealth();

            hostBuilder.ConfigureServices(
                (context, services) =>
            {
                services.AddHealthEndpoints(context.Configuration);
                services.AddSingleton <IStartupFilter>(new DefaultHealthEndpointsStartupFilter());
            });

            return(hostBuilder);
        }
Ejemplo n.º 2
0
        public static IWebHostBuilder ConfigureHealth(this IWebHostBuilder hostBuilder, Action <IHealthBuilder> configureHealth)
        {
            if (_healthBuilt)
            {
                throw new InvalidOperationException("HealthBuilder allows creation only of a single instance of IHealth");
            }

            hostBuilder.ConfigureHealth(
                (context, healthBuilder) =>
            {
                configureHealth(healthBuilder);
            });

            return(hostBuilder);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Adds App Metrics Health services, configuration and middleware to the
        ///     <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" />.
        /// </summary>
        /// <typeparam name="TStartup">The type of the <see cref="IStartupFilter" /> used to configure metrics middleware.</typeparam>
        /// <param name="hostBuilder">The <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" />.</param>
        /// <returns>A reference to this instance after the operation has completed.</returns>
        public static IWebHostBuilder UseHealth <TStartup>(
            this IWebHostBuilder hostBuilder)
            where TStartup : IStartupFilter, new()
        {
            hostBuilder.ConfigureHealth();

            hostBuilder.ConfigureServices(
                (context, services) =>
            {
                services.AddHealthEndpoints(context.Configuration);
                services.AddSingleton <IStartupFilter>(new TStartup());
            });

            return(hostBuilder);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Adds App Metrics Health services, configuration and middleware to the
        ///     <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" />.
        /// </summary>
        /// <param name="hostBuilder">The <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" />.</param>
        /// <param name="configuration">The <see cref="IConfiguration" /> containing <see cref="HealthEndpointsOptions" /></param>
        /// <param name="optionsDelegate">A callback to configure <see cref="HealthEndpointsOptions" />.</param>
        /// <returns>A reference to this instance after the operation has completed.</returns>
        /// <exception cref="ArgumentNullException">
        ///     <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" /> cannot be null
        /// </exception>
        public static IWebHostBuilder UseHealthEndpoints(
            this IWebHostBuilder hostBuilder,
            IConfiguration configuration,
            Action <HealthEndpointsOptions> optionsDelegate)
        {
            hostBuilder.ConfigureHealth();

            hostBuilder.ConfigureServices(
                services =>
            {
                services.AddHealthEndpoints(optionsDelegate, configuration);
                services.AddSingleton <IStartupFilter>(new DefaultHealthEndpointsStartupFilter());
            });

            return(hostBuilder);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Adds App Metrics Health services, configuration and middleware to the
        ///     <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" />.
        /// </summary>
        /// <param name="hostBuilder">The <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" />.</param>
        /// <param name="setupDelegate">A callback to configure <see cref="HealthEndpointsOptions" />.</param>
        /// <returns>A reference to this instance after the operation has completed.</returns>
        /// <exception cref="ArgumentNullException">
        ///     <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" /> cannot be null
        /// </exception>
        public static IWebHostBuilder UseHealthEndpoints(
            this IWebHostBuilder hostBuilder,
            Action <WebHostBuilderContext, HealthEndpointsOptions> setupDelegate)
        {
            hostBuilder.ConfigureHealth();

            hostBuilder.ConfigureServices(
                (context, services) =>
            {
                var endpointOptions = new HealthEndpointsOptions();
                services.AddHealthEndpoints(
                    options => setupDelegate(context, endpointOptions),
                    context.Configuration);
                services.AddSingleton <IStartupFilter>(new DefaultHealthEndpointsStartupFilter());
            });

            return(hostBuilder);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Adds App Metrics Health services, configuration and middleware to the
        ///     <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" />.
        /// </summary>
        /// <typeparam name="TStartup">The type of the <see cref="IStartupFilter" /> used to configure metrics middleware.</typeparam>
        /// <param name="hostBuilder">The <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" />.</param>
        /// <param name="optionsDelegate">A callback to configure <see cref="HealthWebHostOptions" />.</param>
        /// <returns>A reference to this instance after the operation has completed.</returns>
        public static IWebHostBuilder UseHealth <TStartup>(
            this IWebHostBuilder hostBuilder,
            Action <HealthWebHostOptions> optionsDelegate)
            where TStartup : IStartupFilter, new()
        {
            var options = new HealthWebHostOptions();

            hostBuilder.ConfigureHealth();

            hostBuilder.ConfigureServices(
                (context, services) =>
            {
                optionsDelegate(options);

                services.AddHealthEndpoints(options.EndpointOptions, context.Configuration);
                services.AddSingleton <IStartupFilter>(new TStartup());
            });

            return(hostBuilder);
        }