Skip to content

Commit 764b7aa

Browse files
committed
Register services in health check builder
Signed-off-by: Victor Chang <vicchang@nvidia.com>
1 parent e89ebec commit 764b7aa

File tree

3 files changed

+15
-22
lines changed

3 files changed

+15
-22
lines changed

src/Monai.Deploy.Storage.sln

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
11
Microsoft Visual Studio Solution File, Format Version 12.00
2-
<!--
3-
~ Copyright 2022 MONAI Consortium
4-
~
5-
~ Licensed under the Apache License, Version 2.0 (the "License");
6-
~ you may not use this file except in compliance with the License.
7-
~ You may obtain a copy of the License at
8-
~
9-
~ http://www.apache.org/licenses/LICENSE-2.0
10-
~
11-
~ Unless required by applicable law or agreed to in writing, software
12-
~ distributed under the License is distributed on an "AS IS" BASIS,
13-
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
~ See the License for the specific language governing permissions and
15-
~ limitations under the License.
16-
-->
17-
182
# Visual Studio Version 17
193
VisualStudioVersion = 17.1.32210.238
204
MinimumVisualStudioVersion = 10.0.40219.1

src/Plugins/MinIO/HealthCheckBuilder.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
using System;
1817
using Microsoft.Extensions.DependencyInjection;
1918
using Microsoft.Extensions.Diagnostics.HealthChecks;
2019
using Microsoft.Extensions.Logging;
@@ -33,13 +32,12 @@ public override IHealthChecksBuilder Configure(
3332
IEnumerable<string>? tags = null,
3433
TimeSpan? timeout = null)
3534
{
36-
3735
builder.Add(new HealthCheckRegistration(
3836
ConfigurationKeys.StorageServiceName,
3937
serviceProvider =>
4038
{
41-
var minioClientFactory = serviceProvider.GetRequiredService<IMinIoClientFactory>();
4239
var logger = serviceProvider.GetRequiredService<ILogger<MinIoHealthCheck>>();
40+
var minioClientFactory = serviceProvider.GetRequiredService<IMinIoClientFactory>();
4341
return new MinIoHealthCheck(minioClientFactory, logger);
4442
},
4543
failureStatus,

src/Storage/IHealthChecksBuilderExtensions.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,32 @@ public static class IHealthChecksBuilderExtensions
2929
/// Configures health check for the MONAI Deploy Storage Service.
3030
/// </summary>
3131
/// <param name="builder">Instance of <see cref="IHealthChecksBuilder"/>.</param>
32+
/// <param name="serviceCollection">Instance of <see cref="IServiceCollection"/>.</param>
3233
/// <param name="serviceProvider">Instance of <see cref="IServiceProvider"/>.</param>
3334
/// <param name="fullyQualifiedTypeName">Fully qualified type name of the service to use.</param>
3435
/// <returns>Instance of <see cref="IHealthChecksBuilder"/>.</returns>
3536
/// <exception cref="ConfigurationException"></exception>
3637
public static IHealthChecksBuilder AddMonaiDeployStorageHealthCheck(
3738
this IHealthChecksBuilder builder,
39+
IServiceCollection serviceCollection,
3840
string fullyQualifiedTypeName,
3941
HealthStatus? failureStatus = null,
4042
IEnumerable<string>? tags = null,
4143
TimeSpan? timeout = null)
42-
=> AddMonaiDeployStorageHealthCheck(builder, fullyQualifiedTypeName, new FileSystem(), failureStatus, tags, timeout);
44+
=> AddMonaiDeployStorageHealthCheck(builder, serviceCollection, fullyQualifiedTypeName, new FileSystem(), failureStatus, tags, timeout);
4345

4446
/// <summary>
4547
/// Configures health check for the MONAI Deploy Storage Service.
4648
/// </summary>
4749
/// <param name="builder">Instance of <see cref="IHealthChecksBuilder"/>.</param>
50+
/// <param name="serviceCollection">Instance of <see cref="IServiceCollection"/>.</param>
4851
/// <param name="fullyQualifiedTypeName">Fully qualified type name of the service to use.</param>
4952
/// <param name="fileSystem">Instance of <see cref="IFileSystem"/>.</param>
5053
/// <returns>Instance of <see cref="IHealthChecksBuilder"/>.</returns>
5154
/// <exception cref="ConfigurationException"></exception>
5255
public static IHealthChecksBuilder AddMonaiDeployStorageHealthCheck(
5356
this IHealthChecksBuilder builder,
57+
IServiceCollection serviceCollection,
5458
string fullyQualifiedTypeName,
5559
IFileSystem fileSystem,
5660
HealthStatus? failureStatus = null,
@@ -68,18 +72,25 @@ public static IHealthChecksBuilder AddMonaiDeployStorageHealthCheck(
6872
AppDomain.CurrentDomain.AssemblyResolve += resolveEventHandler;
6973

7074
var storageServiceAssembly = IServiceCollectionExtensions.LoadAssemblyFromDisk(IServiceCollectionExtensions.GetAssemblyName(fullyQualifiedTypeName), fileSystem);
71-
var serviceRegistrationType = storageServiceAssembly.GetTypes().FirstOrDefault(p => p.IsSubclassOf(typeof(HealthCheckRegistrationBase)));
75+
var healthCheckBase = storageServiceAssembly.GetTypes().FirstOrDefault(p => p.IsSubclassOf(typeof(HealthCheckRegistrationBase)));
7276

73-
if (serviceRegistrationType is null || Activator.CreateInstance(serviceRegistrationType, fullyQualifiedTypeName) is not HealthCheckRegistrationBase healthCheckBuilder)
77+
if (healthCheckBase is null || Activator.CreateInstance(healthCheckBase, fullyQualifiedTypeName) is not HealthCheckRegistrationBase healthCheckBuilder)
7478
{
7579
throw new ConfigurationException($"Service registrar cannot be found for the configured plug-in '{fullyQualifiedTypeName}'.");
7680
}
81+
var serviceRegistrationType = storageServiceAssembly.GetTypes().FirstOrDefault(p => p.IsSubclassOf(typeof(ServiceRegistrationBase)));
7782

83+
if (serviceRegistrationType is null || Activator.CreateInstance(serviceRegistrationType, fullyQualifiedTypeName) is not ServiceRegistrationBase serviceRegistrar)
84+
{
85+
throw new ConfigurationException($"Service registrar cannot be found for the configured plug-in '{fullyQualifiedTypeName}'.");
86+
}
7887
if (!IServiceCollectionExtensions.IsSupportedType(fullyQualifiedTypeName, storageServiceAssembly))
7988
{
8089
throw new ConfigurationException($"The configured type '{fullyQualifiedTypeName}' does not implement the {typeof(IStorageService).Name} interface.");
8190
}
8291

92+
serviceRegistrar.Configure(serviceCollection);
93+
8394
healthCheckBuilder.Configure(builder, failureStatus, tags, timeout);
8495

8596
AppDomain.CurrentDomain.AssemblyResolve -= resolveEventHandler;

0 commit comments

Comments
 (0)