Skip to content

Commit

Permalink
Add DbContextChecks to Health Checks (#618)
Browse files Browse the repository at this point in the history
This will ensure that the healthcheck endpoint correctly reports the status of the service if a database connection faults
  • Loading branch information
DrizzlyOwl authored Dec 6, 2024
1 parent 215442c commit 9beb5a1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.11" />
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders" Version="0.24.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.9.0" />
</ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions Dfe.Academies.Academisation.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@
if (File.Exists(descriptionsPath)) config.IncludeXmlComments(descriptionsPath);
});

builder.Services.AddHealthChecks();

builder.Services.AddOptions<AuthenticationConfig>();
var apiKeysConfiguration = builder.Configuration.GetSection("AuthenticationConfig");
builder.Services.Configure<AuthenticationConfig>(apiKeysConfiguration);
Expand Down Expand Up @@ -157,6 +155,9 @@
}
);

builder.Services.AddHealthChecks()
.AddDbContextCheck<AcademisationContext>("Academisation Database");

builder.Services.AddSwaggerGen();
builder.Services.ConfigureOptions<SwaggerOptions>();
builder.Services.AddAutoMapper(typeof(AutoMapperProfile));
Expand Down

0 comments on commit 9beb5a1

Please sign in to comment.