-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: deleted startup, usage comes from extension file with various im…
…plementations
- Loading branch information
1 parent
2b0efac
commit 1a67dff
Showing
5 changed files
with
58 additions
and
43 deletions.
There are no files selected for viewing
9 changes: 0 additions & 9 deletions
9
Equinor.SubSurfAppManagementMonitoringNuGet/Config/ApplicationConfig.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
Equinor.SubSurfAppManagementMonitoringNuGet/Controllers/HealthControllerOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Equinor.SubSurfAppManagementMonitoringNuGet.Controllers; | ||
|
||
/// <summary> | ||
/// Represents options that can be passed to the health controller. | ||
/// </summary> | ||
public class HealthControllerOptions | ||
{ | ||
/// <summary> | ||
/// A custom parameter to configure the health controller. | ||
/// </summary> | ||
public string AppName { get; set; } = string.Empty; | ||
} |
42 changes: 41 additions & 1 deletion
42
...ubSurfAppManagementMonitoringNuGet/Extensions/HealthCheckerServiceCollectionExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,58 @@ | ||
using Equinor.SubSurfAppManagementMonitoringNuGet.Controllers; | ||
using Equinor.SubSurfAppManagementMonitoringNuGet.Helpers; | ||
using Equinor.SubSurfAppManagementMonitoringNuGet.Models; | ||
using Equinor.SubSurfAppManagementMonitoringNuGet.Services; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Equinor.SubSurfAppManagementMonitoringNuGet.Extensions; | ||
|
||
public static class HealthCheckerServiceCollectionExtensions | ||
{ | ||
/// <summary> | ||
/// Adds health checks and a health controller to the application, while configuring a custom health checker service. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the custom health checker service that implements <see cref="IHealthCheckerService"/>.</typeparam> | ||
/// <param name="services">The service collection to add the health services to.</param> | ||
/// <param name="configuration">The application configuration used to configure the health services.</param> | ||
/// <returns>An <see cref="IHealthChecksBuilder"/> to further configure health checks.</returns> | ||
/// <exception cref="ArgumentException">Thrown if <typeparamref name="T"/> does not implement <see cref="IHealthCheckerService"/>.</exception> | ||
public static IHealthChecksBuilder AddCustomHealthController<T>(this IServiceCollection services, IConfiguration configuration) | ||
where T : class, IHealthCheckerService | ||
{ | ||
services.AddMvc().AddApplicationPart(typeof(HealthController).Assembly); | ||
var healthChecksBuilder = services.ConfigureHealthServices<T>(configuration); | ||
return healthChecksBuilder; | ||
} | ||
|
||
/// <summary> | ||
/// Adds the default health checker service and integrates it with the health check builder. | ||
/// </summary> | ||
/// <param name="services">The service collection.</param> | ||
public static IHealthChecksBuilder AddDefaultHealthChecker(this IServiceCollection services) | ||
/// <param name="configuration"></param> | ||
/// <param name="applicationName">The name of your application, will show up as the applicationName in the <see cref="ApplicationHealth"/> response</param> | ||
public static IHealthChecksBuilder AddDefaultHealthController(this IServiceCollection services, IConfiguration configuration, string applicationName) | ||
{ | ||
services.AddSingleton<IEnvironment, EnvironmentWrapper>(); | ||
services.AddSingleton(new HealthControllerOptions { AppName = applicationName }); | ||
services.AddMvc().AddApplicationPart(typeof(HealthController).Assembly); | ||
var healthChecksBuilder = services.ConfigureHealthServices<DefaultHealthCheckerService>(configuration); | ||
return healthChecksBuilder; | ||
} | ||
|
||
/// <summary> | ||
/// Configures health-related services, including a custom health checker service and the health controller. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the custom health checker service that implements <see cref="IHealthCheckerService"/>.</typeparam> | ||
/// <param name="services">The service collection to configure.</param> | ||
/// <param name="configuration">The application configuration used to configure the health services.</param> | ||
public static IHealthChecksBuilder ConfigureHealthServices<T>(this IServiceCollection services, IConfiguration configuration) | ||
where T : class, IHealthCheckerService | ||
{ | ||
services.AddTransient<IHealthCheckerService, T>(); | ||
var healthChecksBuilder = services.AddHealthChecks(); | ||
return healthChecksBuilder; | ||
} | ||
|
||
|
||
} |
This file was deleted.
Oops, something went wrong.