Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DbContextChecks to Health Checks #648

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="8.0.8" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageReference Include="Microsoft.Identity.Web" Version="3.1.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public static IServiceCollection AddInfrastructureDependencyGroup(
services.AddDbContext<EdperfContext>(options =>
options.UseSqlServer(connectionString));

AddInfrastructureHealthChecks(services);

return services;
}

Expand Down Expand Up @@ -58,10 +60,17 @@ public static IServiceCollection AddPersonsApiInfrastructureDependencyGroup(
services.AddDbContext<MopContext>(options =>
options.UseSqlServer(connectionString));

AddInfrastructureHealthChecks(services);

// Authentication
services.AddCustomAuthorization(config);

return services;
}

public static void AddInfrastructureHealthChecks(this IServiceCollection services) {
services.AddHealthChecks()
.AddDbContextCheck<MstrContext>("Academies Database");
}
}
}
}
2 changes: 1 addition & 1 deletion PersonsApi/PersonsApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@
<Message Text="$(NSwagOutput)" Condition="'$(NSwagExitCode)' == '0'" Importance="low" />
<Error Text="$(NSwagOutput)" Condition="'$(NSwagExitCode)' != '0'" />
</Target>

</Project>
2 changes: 2 additions & 0 deletions PersonsApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@

logger.LogInformation("Logger is working...");

app.MapHealthChecks("/HealthCheck").AllowAnonymous();

app.Run();
5 changes: 2 additions & 3 deletions PersonsApi/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public void ConfigureServices(IServiceCollection services)
{
configure.Title = "PersonsApi";
});

}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand Down Expand Up @@ -175,10 +174,10 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApiVers
app.UseHttpsRedirection();
app.UseRouting();

app.UseAuthentication();
app.UseAuthentication();
app.UseAuthorization();

app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
}
}
}
}
62 changes: 0 additions & 62 deletions TramsDataApi/Controllers/HealthCheckController.cs

This file was deleted.

2 changes: 2 additions & 0 deletions TramsDataApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@

logger.LogInformation("Logger is working...");

app.MapHealthChecks("/HealthCheck").AllowAnonymous();

app.Run();
Loading