/PlayingWithHealthChecks

Try out the new feature of HealthChecks in ASP.NET Core WebAPI.

Primary LanguageC#

Playing with Health Checks

This is a small WebAPI application to try out the health checks feature.

Separate branch with the .NET Core 2.2 version.

Resources:

The packages I used:
public void ConfigureServices(IServiceCollection services)
{
    ...
    // Install-Package Npgsql.EntityFrameworkCore.PostgreSQL
    services.AddDbContext<DataBaseContext>(options
        => options.UseNpgsql(Configuration.GetConnectionString("PostgreSQL")));
    ...
    // Add: Health checks.
    services
        .AddHealthChecks()
        // Install-Package Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore
        .AddDbContextCheck<DataBaseContext>()
        // Install-Package AspNetCore.HealthChecks.Redis
        .AddRedis(Configuration.GetConnectionString("Redis"))
        // Install-Package AspNetCore.HealthChecks.MySql
        .AddMySql(Configuration.GetConnectionString("MySQL"))
        .AddCheck<RandomHealthCheck>("random");

    // Install-Package AspNetCore.HealthChecks.UI
    services.AddHealthChecksUI(); // Optional to use
}
Portable servers on Windows