@@ -26,6 +26,7 @@ public abstract class JsonConfigurationJob : JobBase
2626 private const string InitializationConfigurationSectionName = "Initialization" ;
2727 private const string GalleryDbConfigurationSectionName = "GalleryDb" ;
2828 private const string StatisticsDbConfigurationSectionName = "StatisticsDb" ;
29+ private const string SupportRequestDbConfigurationSectionName = "SupportRequestDb" ;
2930 private const string ValidationDbConfigurationSectionName = "ValidationDb" ;
3031 private const string ServiceBusConfigurationSectionName = "ServiceBus" ;
3132 private const string ValidationStorageConfigurationSectionName = "ValidationStorage" ;
@@ -111,32 +112,28 @@ protected virtual void ConfigureDefaultJobServices(IServiceCollection services,
111112 {
112113 services . Configure < GalleryDbConfiguration > ( configurationRoot . GetSection ( GalleryDbConfigurationSectionName ) ) ;
113114 services . Configure < StatisticsDbConfiguration > ( configurationRoot . GetSection ( StatisticsDbConfigurationSectionName ) ) ;
115+ services . Configure < SupportRequestDbConfiguration > ( configurationRoot . GetSection ( SupportRequestDbConfigurationSectionName ) ) ;
114116 services . Configure < ValidationDbConfiguration > ( configurationRoot . GetSection ( ValidationDbConfigurationSectionName ) ) ;
115117 services . Configure < ServiceBusConfiguration > ( configurationRoot . GetSection ( ServiceBusConfigurationSectionName ) ) ;
116118 services . Configure < ValidationStorageConfiguration > ( configurationRoot . GetSection ( ValidationStorageConfigurationSectionName ) ) ;
117119
118120 services . AddSingleton ( new TelemetryClient ( ) ) ;
119121 services . AddTransient < ITelemetryClient , TelemetryClientWrapper > ( ) ;
120122
121- services . AddScoped < ISqlConnectionFactory < GalleryDbConfiguration > > ( p =>
122- {
123- return new DelegateSqlConnectionFactory < GalleryDbConfiguration > (
124- CreateSqlConnectionAsync < GalleryDbConfiguration > ,
125- p . GetRequiredService < ILogger < DelegateSqlConnectionFactory < GalleryDbConfiguration > > > ( ) ) ;
126- } ) ;
127-
128- services . AddScoped < ISqlConnectionFactory < StatisticsDbConfiguration > > ( p =>
129- {
130- return new DelegateSqlConnectionFactory < StatisticsDbConfiguration > (
131- CreateSqlConnectionAsync < StatisticsDbConfiguration > ,
132- p . GetRequiredService < ILogger < DelegateSqlConnectionFactory < StatisticsDbConfiguration > > > ( ) ) ;
133- } ) ;
123+ AddScopedSqlConnectionFactory < GalleryDbConfiguration > ( services ) ;
124+ AddScopedSqlConnectionFactory < StatisticsDbConfiguration > ( services ) ;
125+ AddScopedSqlConnectionFactory < SupportRequestDbConfiguration > ( services ) ;
126+ AddScopedSqlConnectionFactory < ValidationDbConfiguration > ( services ) ;
127+ }
134128
135- services . AddScoped < ISqlConnectionFactory < ValidationDbConfiguration > > ( p =>
129+ private void AddScopedSqlConnectionFactory < TDbConfiguration > ( IServiceCollection services )
130+ where TDbConfiguration : IDbConfiguration
131+ {
132+ services . AddScoped < ISqlConnectionFactory < TDbConfiguration > > ( p =>
136133 {
137- return new DelegateSqlConnectionFactory < ValidationDbConfiguration > (
138- CreateSqlConnectionAsync < ValidationDbConfiguration > ,
139- p . GetRequiredService < ILogger < DelegateSqlConnectionFactory < ValidationDbConfiguration > > > ( ) ) ;
134+ return new DelegateSqlConnectionFactory < TDbConfiguration > (
135+ CreateSqlConnectionAsync < TDbConfiguration > ,
136+ p . GetRequiredService < ILogger < DelegateSqlConnectionFactory < TDbConfiguration > > > ( ) ) ;
140137 } ) ;
141138 }
142139
@@ -150,22 +147,19 @@ private void ConfigureLibraries(IServiceCollection services)
150147
151148 protected virtual void RegisterDatabases ( IServiceProvider serviceProvider )
152149 {
153- var galleryDb = serviceProvider . GetRequiredService < IOptionsSnapshot < GalleryDbConfiguration > > ( ) ;
154- if ( ! string . IsNullOrEmpty ( galleryDb . Value ? . ConnectionString ) )
155- {
156- RegisterDatabase < GalleryDbConfiguration > ( serviceProvider ) ;
157- }
158-
159- var statisticsDb = serviceProvider . GetRequiredService < IOptionsSnapshot < StatisticsDbConfiguration > > ( ) ;
160- if ( ! string . IsNullOrEmpty ( statisticsDb . Value ? . ConnectionString ) )
161- {
162- RegisterDatabase < StatisticsDbConfiguration > ( serviceProvider ) ;
163- }
150+ RegisterDatabaseIfConfigured < GalleryDbConfiguration > ( serviceProvider ) ;
151+ RegisterDatabaseIfConfigured < StatisticsDbConfiguration > ( serviceProvider ) ;
152+ RegisterDatabaseIfConfigured < SupportRequestDbConfiguration > ( serviceProvider ) ;
153+ RegisterDatabaseIfConfigured < ValidationDbConfiguration > ( serviceProvider ) ;
154+ }
164155
165- var validationDb = serviceProvider . GetRequiredService < IOptionsSnapshot < ValidationDbConfiguration > > ( ) ;
166- if ( ! string . IsNullOrEmpty ( validationDb . Value ? . ConnectionString ) )
156+ private void RegisterDatabaseIfConfigured < TDbConfiguration > ( IServiceProvider serviceProvider )
157+ where TDbConfiguration : IDbConfiguration
158+ {
159+ var dbConfiguration = serviceProvider . GetRequiredService < IOptionsSnapshot < TDbConfiguration > > ( ) ;
160+ if ( ! string . IsNullOrEmpty ( dbConfiguration . Value ? . ConnectionString ) )
167161 {
168- RegisterDatabase < ValidationDbConfiguration > ( serviceProvider ) ;
162+ RegisterDatabase < TDbConfiguration > ( serviceProvider ) ;
169163 }
170164 }
171165
0 commit comments