Skip to content

Commit

Permalink
Merge pull request #969 from DFE-Digital/feature/health-checks
Browse files Browse the repository at this point in the history
Add DbContextChecks to Health Checks
  • Loading branch information
DrizzlyOwl authored Dec 11, 2024
2 parents 1c1b152 + 4cf6b78 commit 99c8937
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
</PackageReference>
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.9.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.11" />
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="7.6.3" />
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders" Version="0.22.0" />
<PackageReference Include="OfficeOpenXml.Core.ExcelPackage" Version="1.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApiVers
app.UseAuthorization();

app.UseManageFreeSchoolProjectsEndpoints();

app.UseHealthChecks("/health");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ public static IServiceCollection AddDatabase(this IServiceCollection services, I

services.AddScoped<AuditInterceptor, AuditInterceptor>();

AddDbHealthCheck(services);

return services;
}
}

public static void AddDbHealthCheck(IServiceCollection services) {
services.AddHealthChecks()
.AddDbContextCheck<MfspContext>("Manage Free School Projects Database");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,14 @@ public void ConfigureServices(IServiceCollection services)
{
services.AddHttpClient();
services.AddFeatureManagement();
services.AddHealthChecks();
services
.AddRazorPages(options =>
{
options.Conventions.AuthorizeFolder("/");
options.Conventions.AllowAnonymousToPage("/Public/AccessibilityStatement");
options.Conventions.AllowAnonymousToPage("/Public/Cookies");
options.Conventions.AllowAnonymousToPage("/Account/AccessDenied");
})
})
.AddViewOptions(options =>
{
options.HtmlHelperOptions.ClientValidationEnabled = false;
Expand Down Expand Up @@ -118,7 +117,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddScoped<IUpdateProjectPaymentsService, UpdateProjectPaymentsService>();
services.AddScoped<IAddProjectPaymentsService, AddProjectPaymentsService>();
services.AddScoped<IDeleteProjectPaymentsService, DeleteProjectPaymentsService>();
services.AddScoped<IGrantLettersService, GrantLettersService>();
services.AddScoped<IGrantLettersService, GrantLettersService>();
services.AddScoped<IPDGPaymentInfoService, PDGPaymentInfoService>();
services.AddScoped<IBulkEditFileReader, BulkEditFileReader>();
services.AddScoped<IBulkEditFileValidator, BulkEditFileValidator>();
Expand Down Expand Up @@ -184,6 +183,8 @@ public void ConfigureServices(IServiceCollection services)
});

System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);

SetupHealthChecks(services);
}

private void SetupDataprotection(IServiceCollection services)
Expand All @@ -205,6 +206,11 @@ private void SetupDataprotection(IServiceCollection services)
}
}

private static void SetupHealthChecks(IServiceCollection services)
{
services.AddHealthChecks();
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger<Startup> logger)
{
// Ensure we do not lose X-Forwarded-* Headers when behind a Proxy
Expand Down

0 comments on commit 99c8937

Please sign in to comment.