From 36f3b36021b1cdd590e8bbc1609483d326fda7fd Mon Sep 17 00:00:00 2001 From: Will Sugarman Date: Thu, 5 Oct 2023 14:13:31 -0700 Subject: [PATCH] Merge registration methods --- .../DicomSqlServerRegistrationExtensions.cs | 57 +++++++------------ 1 file changed, 21 insertions(+), 36 deletions(-) diff --git a/src/Microsoft.Health.Dicom.SqlServer/Registration/DicomSqlServerRegistrationExtensions.cs b/src/Microsoft.Health.Dicom.SqlServer/Registration/DicomSqlServerRegistrationExtensions.cs index cc9e1c22e6..24c2cb008f 100644 --- a/src/Microsoft.Health.Dicom.SqlServer/Registration/DicomSqlServerRegistrationExtensions.cs +++ b/src/Microsoft.Health.Dicom.SqlServer/Registration/DicomSqlServerRegistrationExtensions.cs @@ -40,38 +40,18 @@ public static IDicomServerBuilder AddSqlServer( IConfiguration configurationRoot, Action configureAction = null) { - IServiceCollection services = EnsureArg.IsNotNull(dicomServerBuilder, nameof(dicomServerBuilder)).Services; - - // Add core SQL services - IConfigurationSection config = EnsureArg - .IsNotNull(configurationRoot, nameof(configurationRoot)) - .GetSection(SqlServerDataStoreConfiguration.SectionName); - - services - .AddSqlServerConnection( - sqlOptions => - { - config.Bind(sqlOptions); - configureAction?.Invoke(sqlOptions); - }) + EnsureArg.IsNotNull(dicomServerBuilder, nameof(dicomServerBuilder)); + EnsureArg.IsNotNull(configurationRoot, nameof(configurationRoot)); + + dicomServerBuilder.Services + .AddCommonSqlServices(sqlOptions => + { + configurationRoot.GetSection(SqlServerDataStoreConfiguration.SectionName).Bind(sqlOptions); + configureAction?.Invoke(sqlOptions); + }) .AddSqlServerManagement() .AddSqlServerApi() - .AddBackgroundSqlSchemaVersionResolver(); - - // Optionally enable workload identity - DicomSqlServerOptions options = new(); - config.Bind(options); - if (options.EnableWorkloadIdentity) - services.EnableWorkloadManagedIdentity(); - - // Add SQL-specific implementations - services - .AddSqlChangeFeedStores() - .AddSqlExtendedQueryTagStores() - .AddSqlExtendedQueryTagErrorStores() - .AddSqlIndexDataStores() - .AddSqlInstanceStores() - .AddSqlPartitionStores() + .AddBackgroundSqlSchemaVersionResolver() .AddSqlQueryStores() .AddSqlWorkitemStores(); @@ -85,12 +65,17 @@ public static IDicomFunctionsBuilder AddSqlServer( EnsureArg.IsNotNull(dicomFunctionsBuilder, nameof(dicomFunctionsBuilder)); EnsureArg.IsNotNull(configureAction, nameof(configureAction)); - IServiceCollection services = dicomFunctionsBuilder.Services; + dicomFunctionsBuilder.Services + .AddCommonSqlServices(configureAction) + .AddForegroundSqlSchemaVersionResolver(); + + return dicomFunctionsBuilder; + } + private static IServiceCollection AddCommonSqlServices(this IServiceCollection services, Action configureAction) + { // Add core SQL services - services - .AddSqlServerConnection(configureAction) - .AddForegroundSqlSchemaVersionResolver(); + services.AddSqlServerConnection(configureAction); // Optionally enable workload identity DicomSqlServerOptions options = new(); @@ -98,7 +83,7 @@ public static IDicomFunctionsBuilder AddSqlServer( if (options.EnableWorkloadIdentity) services.EnableWorkloadManagedIdentity(); - // Add SQL-specific implementations + // Add SQL-specific data store implementations services .AddSqlExtendedQueryTagStores() .AddSqlExtendedQueryTagErrorStores() @@ -107,7 +92,7 @@ public static IDicomFunctionsBuilder AddSqlServer( .AddSqlPartitionStores() .AddSqlChangeFeedStores(); - return dicomFunctionsBuilder; + return services; } private static IServiceCollection AddBackgroundSqlSchemaVersionResolver(this IServiceCollection services)