public HealthCheckService(HealthCheckBuilder builder, IServiceProvider serviceProvider, IServiceScopeFactory serviceScopeFactory) { _builder = builder; _groups = GetGroups().Where(group => group.GroupName != string.Empty).ToList(); _root = GetGroup(string.Empty); _serviceProvider = serviceProvider; _serviceScopeFactory = serviceScopeFactory; }
/// <summary> /// This constructor should only be used when creating a grouped health check builder. /// </summary> public HealthCheckBuilder(HealthCheckBuilder rootBuilder, HealthCheckGroup currentGroup) { Guard.ArgumentNotNull(nameof(rootBuilder), rootBuilder); Guard.ArgumentNotNull(nameof(currentGroup), currentGroup); _checksByName = rootBuilder._checksByName; _currentGroup = currentGroup; _groups = rootBuilder._groups; DefaultCacheDuration = rootBuilder.DefaultCacheDuration; }
public static IServiceCollection AddHealthChecks(this IServiceCollection services, Action <HealthCheckBuilder> checks) { Guard.OperationValid(services.All(descriptor => descriptor.ServiceType != HealthCheckServiceInterface), "AddHealthChecks may only be called once."); var builder = new HealthCheckBuilder(); services.AddSingleton <IHealthCheckService, HealthCheckService>(serviceProvider => { var serviceScopeFactory = serviceProvider.GetService <IServiceScopeFactory>(); return(new HealthCheckService(builder, serviceProvider, serviceScopeFactory)); }); checks(builder); return(services); }
/// <summary> /// Creates a new health check group, to which you can add one or more health /// checks. /// </summary> public HealthCheckBuilder AddHealthCheckGroup(string groupName, Action <HealthCheckBuilder> groupChecks, CheckStatus partialSuccessStatus) { Guard.ArgumentNotNullOrEmpty(nameof(groupName), groupName); Guard.ArgumentNotNull(nameof(groupChecks), groupChecks); Guard.ArgumentValid(partialSuccessStatus != CheckStatus.Unknown, nameof(partialSuccessStatus), "Check status 'Unknown' is not valid for partial success."); Guard.ArgumentValid(!_groups.ContainsKey(groupName), nameof(groupName), $"A group with name '{groupName}' has already been registered."); Guard.OperationValid(_currentGroup.GroupName == string.Empty, "Nested groups are not supported by HealthCheckBuilder."); var group = new HealthCheckGroup(groupName, partialSuccessStatus); _groups.Add(groupName, group); var innerBuilder = new HealthCheckBuilder(this, group); groupChecks(innerBuilder); return(this); }