@@ -7,25 +7,28 @@ namespace RealTimeWeatherMonitoringApp.Infrastructure.Factory;
77
88public class ConfigurationFactory : IConfigurationFactory
99{
10- private const string BotConfigurationFilePath = "Infrastructure/Configuration/configuration.json" ;
11-
1210 private static readonly Lazy < JsonSerializerOptions > JsonOptions = new ( ( ) => new JsonSerializerOptions
1311 {
1412 PropertyNameCaseInsensitive = true ,
1513 Converters = { new JsonStringEnumConverter ( JsonNamingPolicy . CamelCase ) }
1614 } ) ;
1715
18- private readonly Lazy < IEnumerable < BotConfiguration > > _botConfigurations = new ( ( ) =>
16+ private readonly Lazy < IEnumerable < BotConfiguration > > _botConfigurations ;
17+
18+ public ConfigurationFactory ( string configurationFilepath )
1919 {
20- var baseDirectory = AppDomain . CurrentDomain . BaseDirectory ;
21- var fullPath = Path . Combine ( baseDirectory , BotConfigurationFilePath ) ;
22- var jsonText = File . ReadAllText ( fullPath ) ;
20+ _botConfigurations = new Lazy < IEnumerable < BotConfiguration > > ( ( ) =>
21+ {
22+ var baseDirectory = AppDomain . CurrentDomain . BaseDirectory ;
23+ var fullPath = Path . Combine ( baseDirectory , configurationFilepath ) ;
24+ var jsonText = File . ReadAllText ( fullPath ) ;
2325
24- var botDict = JsonSerializer . Deserialize < Dictionary < string , BotConfiguration > > ( jsonText , JsonOptions . Value ) ;
25- return botDict == null
26- ? Enumerable . Empty < BotConfiguration > ( )
27- : botDict . Select ( kvp => kvp . Value with { Name = kvp . Key } ) ;
28- } ) ;
26+ var botDict = JsonSerializer . Deserialize < Dictionary < string , BotConfiguration > > ( jsonText , JsonOptions . Value ) ;
27+ return botDict == null
28+ ? Enumerable . Empty < BotConfiguration > ( )
29+ : botDict . Select ( kvp => kvp . Value with { Name = kvp . Key } ) ;
30+ } ) ;
31+ }
2932
3033 public IEnumerable < BotConfiguration > CreateBotConfigurations ( ) => _botConfigurations . Value ;
3134}
0 commit comments