1- using System . Collections . Generic ;
1+ using System ;
2+ using System . Collections . Generic ;
23using System . Collections . Specialized ;
34using System . Configuration ;
45using System . Linq ;
@@ -8,11 +9,13 @@ namespace Patterns.Configuration
89 public class ConfigurationSource : IConfigurationSource
910 {
1011 private readonly IConfigurationManager _configManager ;
12+ private readonly Func < System . Configuration . Configuration , IConfiguration > _configFactory ;
1113
12- public ConfigurationSource ( IConfigurationManager configManager )
14+ public ConfigurationSource ( IConfigurationManager configManager , Func < System . Configuration . Configuration , IConfiguration > configFactory )
1315 {
1416 _configManager = configManager ;
15- NameValueCollection appSettings = _configManager . AppSettings ;
17+ _configFactory = configFactory ;
18+ NameValueCollection appSettings = _configManager . AppSettings ;
1619 if ( appSettings != null ) AppSettings = appSettings . AllKeys . ToDictionary ( key => key , key => appSettings [ key ] ) ;
1720 var connectionStrings = _configManager . ConnectionStrings ;
1821 if ( connectionStrings != null ) ConnectionStrings = connectionStrings . OfType < ConnectionStringSettings > ( ) . ToDictionary ( settings => settings . Name , settings => settings ) ;
@@ -34,22 +37,22 @@ public virtual TSection GetSection<TSection>(string sectionName) where TSection
3437
3538 public virtual IConfiguration OpenExeConfiguration ( string exePath )
3639 {
37- return new ConfigurationWrapper ( _configManager . OpenExeConfiguration ( exePath ) ) ;
40+ return _configFactory ( _configManager . OpenExeConfiguration ( exePath ) ) ;
3841 }
3942
4043 public virtual IConfiguration OpenExeConfiguration ( ConfigurationUserLevel userLevel )
4144 {
42- return new ConfigurationWrapper ( _configManager . OpenExeConfiguration ( userLevel ) ) ;
45+ return _configFactory ( _configManager . OpenExeConfiguration ( userLevel ) ) ;
4346 }
4447
4548 public virtual IConfiguration OpenMachineConfiguration ( )
4649 {
47- return new ConfigurationWrapper ( _configManager . OpenMachineConfiguration ( ) ) ;
50+ return _configFactory ( _configManager . OpenMachineConfiguration ( ) ) ;
4851 }
4952
5053 public virtual IConfiguration OpenMappedExeConfiguration ( ExeConfigurationFileMap fileMap , ConfigurationUserLevel userLevel )
5154 {
52- return new ConfigurationWrapper ( _configManager . OpenMappedExeConfiguration ( fileMap , userLevel ) ) ;
55+ return _configFactory ( _configManager . OpenMappedExeConfiguration ( fileMap , userLevel ) ) ;
5356 }
5457
5558 public virtual void RefreshSection ( string sectionName )
0 commit comments