private void AddHealthChecks(IServiceCollection services) { services.AddHealthChecksUI(); var healthChecks = services.AddHealthChecks().AddCheck("self", () => HealthCheckResult.Healthy()); var applications = new Dto.RegisteredApplicationsDto(); Configuration.Bind("RegisteredApplications", applications); var canCheck = applications.Applications.Where(w => !string.IsNullOrEmpty(w.HealthCheckUrl)).ToList(); canCheck.ForEach(f => healthChecks.AddUrlGroup(new Uri(f.HealthCheckUrl), name: $"{f.RouteName}-check", tags: new string[] { $"{f.RouteName}-api" })); services.Configure <HealthCheckPublisherOptions>(options => { options.Period = new TimeSpan(0, 0, 4); options.Delay = TimeSpan.FromSeconds(2); options.Timeout = new TimeSpan(0, 0, 10); // options.Predicate = (check) => check.Tags.Contains("ready"); }); const string HealthCheckServiceAssembly = "Microsoft.Extensions.Diagnostics.HealthChecks.HealthCheckPublisherHostedService"; services.TryAddEnumerable( ServiceDescriptor.Singleton(typeof(IHostedService), typeof(HealthCheckPublisherOptions).Assembly .GetType(HealthCheckServiceAssembly))); services.AddSingleton <IHealthCheckPublisher, ReadinessPublisher>(); }
public ApplicationController(IOptions <Dto.RegisteredApplicationsDto> registeredApplications, Services.IApplicationService applicationService, ILogger <ApplicationController> logger) { _registeredApplications = registeredApplications.Value; _applicationService = applicationService; _logger = logger; }