2424
2525namespace Monai . Deploy . Storage
2626{
27+ [ Flags ]
28+ public enum HealthCheckOptions
29+ {
30+ None = 0 ,
31+ ServiceHealthCheck = 1 ,
32+ AdminServiceHealthCheck = 2 ,
33+ }
34+
2735 public static class IServiceCollectionExtensions
2836 {
2937 /// <summary>
@@ -36,11 +44,11 @@ public static class IServiceCollectionExtensions
3644 public static IServiceCollection AddMonaiDeployStorageService (
3745 this IServiceCollection services ,
3846 string fullyQualifiedTypeName ,
39- bool registerHealthCheck = true ,
47+ HealthCheckOptions healthCheckOptions = HealthCheckOptions . ServiceHealthCheck | HealthCheckOptions . AdminServiceHealthCheck ,
4048 HealthStatus ? failureStatus = null ,
4149 IEnumerable < string > ? tags = null ,
4250 TimeSpan ? timeout = null )
43- => AddMonaiDeployStorageService ( services , fullyQualifiedTypeName , new FileSystem ( ) , registerHealthCheck , failureStatus , tags , timeout ) ;
51+ => AddMonaiDeployStorageService ( services , fullyQualifiedTypeName , new FileSystem ( ) , healthCheckOptions , failureStatus , tags , timeout ) ;
4452
4553 /// <summary>
4654 /// Configures all dependencies required for the MONAI Deploy Storage Service.
@@ -54,7 +62,7 @@ public static IServiceCollection AddMonaiDeployStorageService(
5462 this IServiceCollection services ,
5563 string fullyQualifiedTypeName ,
5664 IFileSystem fileSystem ,
57- bool registerHealthCheck = true ,
65+ HealthCheckOptions healthCheckOptions = HealthCheckOptions . ServiceHealthCheck | HealthCheckOptions . AdminServiceHealthCheck ,
5866 HealthStatus ? failureStatus = null ,
5967 IEnumerable < string > ? tags = null ,
6068 TimeSpan ? timeout = null )
@@ -78,23 +86,26 @@ public static IServiceCollection AddMonaiDeployStorageService(
7886
7987 RegisterServices ( services , fullyQualifiedTypeName , storageServiceAssembly ) ;
8088
81- if ( registerHealthCheck )
82- {
83- RegisterHealtChecks ( services , fullyQualifiedTypeName , storageServiceAssembly , failureStatus , tags , timeout ) ;
84- }
89+ RegisterHealtChecks ( healthCheckOptions , services , fullyQualifiedTypeName , storageServiceAssembly , failureStatus , tags , timeout ) ;
8590
8691 AppDomain . CurrentDomain . AssemblyResolve -= resolveEventHandler ;
8792 return services ;
8893 }
8994
9095 private static void RegisterHealtChecks (
96+ HealthCheckOptions healthCheckOptions ,
9197 IServiceCollection services ,
9298 string fullyQualifiedTypeName ,
9399 Assembly storageServiceAssembly ,
94100 HealthStatus ? failureStatus = null ,
95101 IEnumerable < string > ? tags = null ,
96102 TimeSpan ? timeout = null )
97103 {
104+ if ( healthCheckOptions == HealthCheckOptions . None )
105+ {
106+ return ;
107+ }
108+
98109 var healthCheckBase = storageServiceAssembly . GetTypes ( ) . FirstOrDefault ( p => p . IsSubclassOf ( typeof ( HealthCheckRegistrationBase ) ) ) ;
99110
100111 if ( healthCheckBase is null || Activator . CreateInstance ( healthCheckBase ) is not HealthCheckRegistrationBase healthCheckBuilderBase )
@@ -103,7 +114,16 @@ private static void RegisterHealtChecks(
103114 }
104115
105116 var healthCheckBuilder = services . AddHealthChecks ( ) ;
106- healthCheckBuilderBase . Configure ( healthCheckBuilder , failureStatus , tags , timeout ) ;
117+
118+ if ( healthCheckOptions . HasFlag ( HealthCheckOptions . ServiceHealthCheck ) )
119+ {
120+ healthCheckBuilderBase . ConfigureHealthCheck ( healthCheckBuilder , failureStatus , tags , timeout ) ;
121+ }
122+
123+ if ( healthCheckOptions . HasFlag ( HealthCheckOptions . AdminServiceHealthCheck ) )
124+ {
125+ healthCheckBuilderBase . ConfigureAdminHealthCheck ( healthCheckBuilder , failureStatus , tags , timeout ) ;
126+ }
107127 }
108128
109129 private static void RegisterServices ( IServiceCollection services , string fullyQualifiedTypeName , Assembly storageServiceAssembly )
0 commit comments