Example #1
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));
        }
 public async ValueTask <IHealthCheckResult> RunCheckAsync(CachedHealthCheck healthCheck,
                                                           CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var scope = GetServiceScope())
     {
         return(await RunCheckAsync(scope.ServiceProvider, healthCheck, cancellationToken).ConfigureAwait(false));
     }
 }
Example #4
0
        /// <summary>
        ///     Registers a concrete health check to the builder.
        /// </summary>
        public HealthCheckBuilder AddCheck(string checkName, IHealthCheck check, TimeSpan cacheDuration)
        {
            Guard.ArgumentNotNullOrEmpty(nameof(checkName), checkName);
            Guard.ArgumentNotNull(nameof(check), check);
            Guard.ArgumentValid(!_checksByName.ContainsKey(checkName), nameof(checkName),
                                $"A check with name '{checkName}' has already been registered.");

            var namedCheck = CachedHealthCheck.FromHealthCheck(checkName, cacheDuration, check);

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

            return(this);
        }