55using System . Reflection ;
66using System . Text ;
77using Microsoft . Extensions . Configuration ;
8- using Microsoft . Extensions . Configuration . EnvironmentVariables ;
9- using Microsoft . VisualBasic ;
108using Serilog . Events ;
119
1210namespace SqlStreamStore . Server
1311{
1412 internal class SqlStreamStoreServerConfiguration
1513 {
16- private readonly static string [ ] s_sensitiveKeys = typeof ( ConfigurationData ) . GetProperties ( )
14+ private static readonly string [ ] s_sensitiveKeys = typeof ( ConfigurationData ) . GetProperties ( )
1715 . Where ( property => property . GetCustomAttributes < SensitiveAttribute > ( ) . Any ( ) )
1816 . Select ( property => property . Name )
1917 . ToArray ( ) ;
@@ -52,9 +50,9 @@ void Log(string logName, IDictionary<string, string> data)
5250
5351 _configuration = new ConfigurationData (
5452 new ConfigurationBuilder ( )
55- . Add ( new DefaultConfigurationSource ( Log ) )
56- . Add ( new CommandLineConfigurationSource ( args , Log ) )
57- . Add ( new EnvironmentVariablesConfigurationSource ( environment , Log ) )
53+ . Add ( new Default ( Log ) )
54+ . Add ( new CommandLine ( args , Log ) )
55+ . Add ( new EnvironmentVariables ( environment , Log ) )
5856 . Build ( ) ) ;
5957 }
6058
@@ -84,9 +82,7 @@ public override string ToString()
8482 }
8583 }
8684 . Concat (
87- _values . Keys
88- . Where ( s_allKeys . Contains )
89- . OrderBy ( key => key )
85+ s_allKeys
9086 . Select ( key => new [ ] { delimiter , key , _values [ key ] . value , _values [ key ] . source } ) )
9187 . Aggregate (
9288 new StringBuilder ( ) . AppendLine ( "SQL Stream Store Configuration:" ) ,
@@ -124,11 +120,11 @@ public ConfigurationData(IConfigurationRoot configuration)
124120 }
125121 }
126122
127- private class DefaultConfigurationSource : ConfigurationProvider , IConfigurationSource
123+ private class Default : IConfigurationSource
128124 {
129125 private readonly Action < string , IDictionary < string , string > > _log ;
130126
131- public DefaultConfigurationSource ( Action < string , IDictionary < string , string > > log )
127+ public Default ( Action < string , IDictionary < string , string > > log )
132128 {
133129 if ( log == null )
134130 {
@@ -138,7 +134,19 @@ public DefaultConfigurationSource(Action<string, IDictionary<string, string>> lo
138134 _log = log ;
139135 }
140136
141- public IConfigurationProvider Build ( IConfigurationBuilder builder ) => this ;
137+ public IConfigurationProvider Build ( IConfigurationBuilder builder ) =>
138+ new DefaultConfigurtationProvider ( _log ) ;
139+ }
140+
141+ private class DefaultConfigurtationProvider : ConfigurationProvider
142+ {
143+ private readonly Action < string , IDictionary < string , string > > _log ;
144+
145+ public DefaultConfigurtationProvider ( Action < string , IDictionary < string , string > > log )
146+ {
147+ if ( log == null ) throw new ArgumentNullException ( nameof ( log ) ) ;
148+ _log = log ;
149+ }
142150
143151 public override void Load ( )
144152 {
@@ -151,16 +159,16 @@ public override void Load()
151159 [ nameof ( UseCanonicalUris ) ] = default
152160 } ;
153161
154- _log ( nameof ( DefaultConfigurationSource ) , Data ) ;
162+ _log ( nameof ( Default ) , Data ) ;
155163 }
156164 }
157165
158- private class CommandLineConfigurationSource : IConfigurationSource
166+ private class CommandLine : IConfigurationSource
159167 {
160168 private readonly IEnumerable < string > _args ;
161169 private readonly Action < string , IDictionary < string , string > > _log ;
162170
163- public CommandLineConfigurationSource (
171+ public CommandLine (
164172 IEnumerable < string > args ,
165173 Action < string , IDictionary < string , string > > log )
166174 {
@@ -205,17 +213,17 @@ public override void Load()
205213
206214 Data = Data . Keys . ToDictionary ( Computerize , x => Data [ x ] ) ;
207215
208- _log ( nameof ( CommandLineConfigurationSource ) , Data ) ;
216+ _log ( nameof ( CommandLine ) , Data ) ;
209217 }
210218 }
211219
212- private class EnvironmentVariablesConfigurationSource : IConfigurationSource
220+ private class EnvironmentVariables : IConfigurationSource
213221 {
214222 private readonly IDictionary _environment ;
215223 private readonly Action < string , IDictionary < string , string > > _log ;
216224 public string Prefix { get ; set ; } = "SQLSTREAMSTORE" ;
217225
218- public EnvironmentVariablesConfigurationSource (
226+ public EnvironmentVariables (
219227 IDictionary environment ,
220228 Action < string , IDictionary < string , string > > log )
221229 {
@@ -275,7 +283,7 @@ where key.StartsWith(_prefix)
275283 } )
276284 . ToDictionary ( x => x . key , x => x . value ) ;
277285
278- _log ( nameof ( EnvironmentVariablesConfigurationSource ) , Data ) ;
286+ _log ( nameof ( EnvironmentVariables ) , Data ) ;
279287 }
280288 }
281289
0 commit comments