Skip to content

Commit

Permalink
Refactor healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
Layoric committed Nov 26, 2024
1 parent d27cf90 commit e607df3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 18 additions & 7 deletions MyApp/Configure.HealthCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,32 @@ namespace MyApp;

public class ConfigureHealthCheck : IHostingStartup
{
public class HealthCheck : IHealthCheck
{
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken token = default)
{
// Perform health check logic here
return HealthCheckResult.Healthy();
}
}

public void Configure(IWebHostBuilder builder)
{
builder.ConfigureServices(services =>
{
services.AddHealthChecks()
.AddCheck<HealthCheck>("HealthCheck");

services.AddTransient<IStartupFilter, StartupFilter>();
});
}
}

public class HealthCheck : IHealthCheck
{
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)

public class StartupFilter : IStartupFilter
{
// Perform health check logic here
return HealthCheckResult.Healthy();
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
=> app => {
app.UseEndpoints(endpoints => endpoints.MapHealthChecks("/up"));
next(app);
};
}
}
2 changes: 0 additions & 2 deletions MyApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@
// Add additional endpoints required by the Identity /Account Razor components.
app.MapAdditionalIdentityEndpoints();

app.MapHealthChecks("/up");

app.UseServiceStack(new AppHost(), options => {
options.MapEndpoints();
});
Expand Down

0 comments on commit e607df3

Please sign in to comment.