From e3340b7c98510ab8441aff9a6084038899d5bbe2 Mon Sep 17 00:00:00 2001 From: "Janus C. H. Knudsen" Date: Tue, 11 Feb 2025 23:32:28 +0100 Subject: [PATCH] Adds comments --- .../JsonConfigProvider/JsonConfigExtension.cs | 8 +++++++ .../SmartConfigExtension.cs | 19 ++++++++++++----- .../SmartConfigProvider/SmartConfigOptions.cs | 21 +++++++++++++++++-- .../SmartConfigProvider.cs | 10 +++++++++ .../SmartConfigProviderTests.cs | 3 +-- 5 files changed, 52 insertions(+), 9 deletions(-) diff --git a/Core/Configurations/JsonConfigProvider/JsonConfigExtension.cs b/Core/Configurations/JsonConfigProvider/JsonConfigExtension.cs index 9061f17..0a305d6 100644 --- a/Core/Configurations/JsonConfigProvider/JsonConfigExtension.cs +++ b/Core/Configurations/JsonConfigProvider/JsonConfigExtension.cs @@ -6,6 +6,14 @@ namespace Core.Configurations.JsonConfigProvider { public static class JsonConfigExtension { + /// + /// Adds a JSON configuration source to the configuration builder. + /// + /// The configuration builder to add to + /// Path to the JSON configuration file. Defaults to "appconfiguration.json" + /// If true, the configuration file is optional. Defaults to true + /// If true, the configuration will be reloaded when the file changes. Defaults to false + /// The configuration builder public static IConfigurationBuilder AddJsonFile(this IConfigurationBuilder builder, string configurationFilePath = "appconfiguration.json", bool? optional = true, bool? reloadOnChange = false) { return builder.AddProvider(new JsonConfigProvider(builder, configurationFilePath, optional ?? true, reloadOnChange ?? false)); diff --git a/Core/Configurations/SmartConfigProvider/SmartConfigExtension.cs b/Core/Configurations/SmartConfigProvider/SmartConfigExtension.cs index dc5ebab..781c3b3 100644 --- a/Core/Configurations/SmartConfigProvider/SmartConfigExtension.cs +++ b/Core/Configurations/SmartConfigProvider/SmartConfigExtension.cs @@ -1,18 +1,27 @@ namespace Core.Configurations.SmartConfig { + /// + /// Extension methods for adding smart configuration providers to IConfigurationBuilder. + /// public static class SmartConfigExtension { /// - /// + /// Adds a smart configuration provider using a connection string from appsettings. /// - /// - /// Name of key - /// If this is different than the default ConnectionStrings-element, then configure it. - /// + /// The configuration builder to add to + /// The key to find the connection string in the ConnectionStrings section. Defaults to "DefaultConnection" + /// Optional path to configuration file if different from default appsettings location + /// The configuration builder public static IConfigurationBuilder AddSmartConfig(this IConfigurationBuilder builder, string configKey = "DefaultConnection", string path = null) { return builder.AddProvider(new SmartConfigProvider(builder, configKey, path)); } + /// + /// Adds a smart configuration provider with custom configuration options. + /// + /// The configuration builder to add to + /// Action to configure the smart configuration options + /// The configuration builder public static IConfigurationBuilder AddSmartConfig(this IConfigurationBuilder builder, Action setupAction) { var options = new SmartConfigOptions(); diff --git a/Core/Configurations/SmartConfigProvider/SmartConfigOptions.cs b/Core/Configurations/SmartConfigProvider/SmartConfigOptions.cs index 1f9f60f..98126bc 100644 --- a/Core/Configurations/SmartConfigProvider/SmartConfigOptions.cs +++ b/Core/Configurations/SmartConfigProvider/SmartConfigOptions.cs @@ -1,22 +1,39 @@ namespace Core.Configurations.SmartConfig { + /// + /// Configuration options for setting up smart configuration providers. + /// Provides fluent configuration methods for specifying the repository type and settings. + /// public class SmartConfigOptions { private SmartConfiguration.IConfigurationRepository _repository; internal string _configKey; + /// + /// Configures the smart configuration to use PostgreSQL as the configuration store. + /// + /// The configuration key used to find the connection string + /// The configuration options instance for method chaining public SmartConfigOptions UsePostgres(string configKey) { _configKey = configKey; _repository = new Configurations.SmartConfigProvider.Repositories.PostgresConfigurationRepository(); return this; } - + /// + /// Configures the smart configuration to use SQL Server as the configuration store. + /// + /// The configuration options instance for method chaining + /// This feature is not yet implemented public SmartConfigOptions UseSqlServer() { throw new NotImplementedException(); } - + /// + /// Configures the smart configuration to use a custom configuration repository. + /// + /// The configuration repository to use + /// The configuration options instance for method chaining public SmartConfigOptions UseRepository(SmartConfiguration.IConfigurationRepository repository) { _repository = repository; diff --git a/Core/Configurations/SmartConfigProvider/SmartConfigProvider.cs b/Core/Configurations/SmartConfigProvider/SmartConfigProvider.cs index 72a1ad7..7f9c655 100644 --- a/Core/Configurations/SmartConfigProvider/SmartConfigProvider.cs +++ b/Core/Configurations/SmartConfigProvider/SmartConfigProvider.cs @@ -5,6 +5,16 @@ using Newtonsoft.Json.Linq; namespace Core.Configurations.SmartConfig { + /// + /// Configuration provider that loads configuration from a smart configuration source (e.g. database). + /// The provider reads connection details from a JSON file and uses them to connect to a configuration repository. + /// + /// + /// The provider supports multiple initialization methods: + /// - Through SmartConfigOptions for flexible repository configuration + /// - Through direct configuration key and file path + /// Configuration is loaded from the repository during Build() and converted to a JSON structure. + /// public class SmartConfigProvider : IConfigurationProvider { string _configKey; diff --git a/Tests/ConfigurationTests/SmartConfigProviderTests.cs b/Tests/ConfigurationTests/SmartConfigProviderTests.cs index a7c996a..3bc95e8 100644 --- a/Tests/ConfigurationTests/SmartConfigProviderTests.cs +++ b/Tests/ConfigurationTests/SmartConfigProviderTests.cs @@ -1,13 +1,11 @@ using Core.Configurations.SmartConfig; using Core.Configurations; using FluentAssertions; -using Newtonsoft.Json.Linq; using Core.Configurations.JsonConfigProvider; using Autofac; using System.Data; using Insight.Database; using Npgsql; -using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Tests.ConfigurationTests { @@ -26,6 +24,7 @@ namespace Tests.ConfigurationTests var actualFeature = config.Get("Database:UseSSL"); } + [TestMethod] public void Get_ShouldReturnCorrectValueAsBool() {