From 4a75b9af674c34f23e29a6491948e7c5c6f9851b Mon Sep 17 00:00:00 2001 From: Zohar Peled Date: Sun, 29 Jun 2025 19:13:46 +0300 Subject: [PATCH] Refactored ConfigurationService, updated To Consider comment in Services --- .../AutoEntityGenerator.csproj | 1 + AutoEntityGenerator/ConfigurationService.cs | 28 ++++++++----------- AutoEntityGenerator/Services.cs | 2 +- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/AutoEntityGenerator/AutoEntityGenerator.csproj b/AutoEntityGenerator/AutoEntityGenerator.csproj index f3e7e88..d73c4db 100644 --- a/AutoEntityGenerator/AutoEntityGenerator.csproj +++ b/AutoEntityGenerator/AutoEntityGenerator.csproj @@ -3,6 +3,7 @@ netstandard2.0 true + latests diff --git a/AutoEntityGenerator/ConfigurationService.cs b/AutoEntityGenerator/ConfigurationService.cs index ddfe3b5..19f4d06 100644 --- a/AutoEntityGenerator/ConfigurationService.cs +++ b/AutoEntityGenerator/ConfigurationService.cs @@ -11,6 +11,7 @@ namespace AutoEntityGenerator internal class ConfigurationService : IConfigurationSaver { private const string FileName = "appSettings.json"; + private const string DefaultDestinationFolder = "Generated"; private readonly string _basePath; private readonly string _fullFilePath; private readonly JsonSerializerOptions _jsonOptions; @@ -30,8 +31,17 @@ public ConfigurationService() } public IAppSettings Load() + => LoadFromFile() ?? new AppSettings() + { + DestinationFolder = DefaultDestinationFolder, + MinimumLogLevel = LogLevel.Information, + RequestSuffix = "Request", + ResponseSuffix = "Response", + OpenGeneratedFiles = true + }; + + private IAppSettings LoadFromFile() { - const string DefaultDestinationFolder = "Generated"; IAppSettings settings = null; if (File.Exists(_fullFilePath)) { @@ -53,24 +63,10 @@ public IAppSettings Load() _deferredException = ex; } } - - if (settings is null) - { - settings = new AppSettings() - { - DestinationFolder = DefaultDestinationFolder, - MinimumLogLevel = LogLevel.Information, - RequestSuffix = "Request", - ResponseSuffix = "Response", - OpenGeneratedFiles = true - }; - } - - return settings; } - // TO Consider: Moving validation from UI to common to reduce code repitition. + // TO Consider: Move validation from UI to common to reduce code repitition. private bool IsDestinationFolderValid(string destinationFolder) { return !destinationFolder.Any(c => Path.GetInvalidPathChars().Contains(c)) && diff --git a/AutoEntityGenerator/Services.cs b/AutoEntityGenerator/Services.cs index 2b62368..9ec4352 100644 --- a/AutoEntityGenerator/Services.cs +++ b/AutoEntityGenerator/Services.cs @@ -45,7 +45,7 @@ private void ConfigureServices() .AddUI(); } - // TO Consider: Switch to using Visual studio's Activity log instead. + // TO Consider: Switch to using file based log: Serilog / Nlog / Visual studio's Activity log. private Services AddLogger() { const string sourceName = nameof(AutoEntityGenerator);