public async ValueTask <IHealthCheckResult> RunCheckAsync(CachedHealthCheck healthCheck, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var scope = GetServiceScope())
     {
         return(await RunCheckAsync(scope.ServiceProvider, healthCheck, cancellationToken).ConfigureAwait(false));
     }
 }
        /// <summary>
        /// Registers a health check type that will later be resolved via dependency
        /// injection.
        /// </summary>
        public HealthCheckBuilder AddCheck <TCheck>(string checkName, TimeSpan cacheDuration) where TCheck : class, IHealthCheck
        {
            Guard.ArgumentNotNullOrEmpty(nameof(checkName), checkName);
            Guard.ArgumentValid(!_checksByName.ContainsKey(checkName), nameof(checkName), $"A check with name '{checkName}' has already been registered.");

            var namedCheck = CachedHealthCheck.FromType(checkName, cacheDuration, typeof(TCheck));

            _checksByName.Add(checkName, namedCheck);
            _currentGroup.ChecksInternal.Add(namedCheck);

            return(this);
        }
Пример #3
0
        public static ValueTask <IHealthCheckResult> RunAsync(this CachedHealthCheck check, IServiceProvider serviceProvider)
        {
            Guard.ArgumentNotNull(nameof(check), check);

            return(check.RunAsync(serviceProvider, CancellationToken.None));
        }
        /// <summary>
        /// Uses the provided service provider and executes the provided check.
        /// </summary>
        public ValueTask <IHealthCheckResult> RunCheckAsync(IServiceProvider serviceProvider, CachedHealthCheck healthCheck, CancellationToken cancellationToken = default(CancellationToken))
        {
            Guard.ArgumentNotNull(nameof(serviceProvider), serviceProvider);
            Guard.ArgumentNotNull(nameof(healthCheck), healthCheck);

            return(healthCheck.RunAsync(serviceProvider, cancellationToken));
        }