using LINGYUN.Abp.LocalizationManagement; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.HealthChecks; using System; using System.Threading; using System.Threading.Tasks; namespace LINGYUN.Abp.MicroService.LocalizationService; public class ServiceHealthCheck : IHealthCheck { private readonly IServiceScopeFactory _scopeFactory; public ServiceHealthCheck(IServiceScopeFactory scopeFactory) { _scopeFactory = scopeFactory; } public async virtual Task CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) { try { using var scope = _scopeFactory.CreateScope(); var repo = scope.ServiceProvider.GetRequiredService(); var _ = await repo.GetCountAsync(cancellationToken); return HealthCheckResult.Healthy(); } catch (Exception ex) { return new HealthCheckResult(context.Registration.FailureStatus, exception: ex); } } }