From 9beb5a1fb7606bac5fafeb336e06d4f44080d517 Mon Sep 17 00:00:00 2001
From: Ash Davies <3853061+DrizzlyOwl@users.noreply.github.com>
Date: Fri, 6 Dec 2024 15:57:07 +0000
Subject: [PATCH] Add DbContextChecks to Health Checks (#618)
This will ensure that the healthcheck endpoint correctly reports the status of the service if a database connection faults
---
.../Dfe.Academies.Academisation.WebApi.csproj | 1 +
Dfe.Academies.Academisation.WebApi/Program.cs | 5 +++--
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/Dfe.Academies.Academisation.WebApi/Dfe.Academies.Academisation.WebApi.csproj b/Dfe.Academies.Academisation.WebApi/Dfe.Academies.Academisation.WebApi.csproj
index 5cda8511..963e7ec6 100644
--- a/Dfe.Academies.Academisation.WebApi/Dfe.Academies.Academisation.WebApi.csproj
+++ b/Dfe.Academies.Academisation.WebApi/Dfe.Academies.Academisation.WebApi.csproj
@@ -26,6 +26,7 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
+
diff --git a/Dfe.Academies.Academisation.WebApi/Program.cs b/Dfe.Academies.Academisation.WebApi/Program.cs
index 0471ea44..1c095f79 100644
--- a/Dfe.Academies.Academisation.WebApi/Program.cs
+++ b/Dfe.Academies.Academisation.WebApi/Program.cs
@@ -97,8 +97,6 @@
if (File.Exists(descriptionsPath)) config.IncludeXmlComments(descriptionsPath);
});
-builder.Services.AddHealthChecks();
-
builder.Services.AddOptions();
var apiKeysConfiguration = builder.Configuration.GetSection("AuthenticationConfig");
builder.Services.Configure(apiKeysConfiguration);
@@ -157,6 +155,9 @@
}
);
+builder.Services.AddHealthChecks()
+ .AddDbContextCheck("Academisation Database");
+
builder.Services.AddSwaggerGen();
builder.Services.ConfigureOptions();
builder.Services.AddAutoMapper(typeof(AutoMapperProfile));