feat: add health checks for database connectivity

This commit is contained in:
2025-12-30 21:19:10 -05:00
parent 011b523fd3
commit cab1b170c1
2 changed files with 6 additions and 0 deletions
+5
View File
@@ -30,6 +30,9 @@ namespace SharpbinV3.Server
builder.Services.AddScoped<IUserService, UserService>(); builder.Services.AddScoped<IUserService, UserService>();
builder.Services.AddScoped<IAuthService, AuthService>(); builder.Services.AddScoped<IAuthService, AuthService>();
builder.Services.AddScoped<IPasteService, PasteService>(); builder.Services.AddScoped<IPasteService, PasteService>();
builder.Services.AddHealthChecks()
.AddDbContextCheck<AppDbContext>("Database");
builder.Services builder.Services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
@@ -105,6 +108,8 @@ namespace SharpbinV3.Server
db.Database.Migrate(); db.Database.Migrate();
} }
app.MapHealthChecks("/health");
app.Run(); app.Run();
} }
} }
@@ -25,6 +25,7 @@
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="10.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" /> <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.15.0" /> <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.15.0" />
</ItemGroup> </ItemGroup>