zhaolei
2020-11-20 4a2e5b9a21940f11757be37d99f0944e240e908b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using Bootstrap.Admin.HealthChecks;
using Microsoft.Extensions.Configuration;
 
namespace Microsoft.Extensions.DependencyInjection
{
    /// <summary>
    /// 健康检查扩展类
    /// </summary>
    public static class HealthChecksBuilderExtensions
    {
        /// <summary>
        /// 添加 BootstrapAdmin 健康检查
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        public static IServiceCollection AddAdminHealthChecks(this IServiceCollection services)
        {
            var builder = services.AddHealthChecks();
            builder.AddCheck<DBHealthCheck>("db");
            builder.AddBootstrapAdminHealthChecks();
 
            var config = services.BuildServiceProvider().GetRequiredService<IConfiguration>();
            var checkGitee = config.GetValue("GiteeHealthChecks", false);
            if (checkGitee) builder.AddCheck<GiteeHttpHealthCheck>("Gitee");
            return services;
        }
    }
}