2025-02-18 16:23:08 +01:00
|
|
|
|
namespace Core.Configurations.SmartConfigProvider
|
2025-02-02 23:13:17 +01:00
|
|
|
|
{
|
2025-02-11 23:32:28 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Extension methods for adding smart configuration providers to IConfigurationBuilder.
|
|
|
|
|
|
/// </summary>
|
2025-02-02 23:13:17 +01:00
|
|
|
|
public static class SmartConfigExtension
|
|
|
|
|
|
{
|
2025-02-11 19:34:45 +01:00
|
|
|
|
/// <summary>
|
2025-02-11 23:32:28 +01:00
|
|
|
|
/// Adds a smart configuration provider using a connection string from appsettings.
|
2025-02-11 19:34:45 +01:00
|
|
|
|
/// </summary>
|
2025-02-11 23:32:28 +01:00
|
|
|
|
/// <param name="builder">The configuration builder to add to</param>
|
|
|
|
|
|
/// <param name="configKey">The key to find the connection string in the ConnectionStrings section. Defaults to "DefaultConnection"</param>
|
|
|
|
|
|
/// <param name="path">Optional path to configuration file if different from default appsettings location</param>
|
|
|
|
|
|
/// <returns>The configuration builder</returns>
|
2025-02-02 23:13:17 +01:00
|
|
|
|
public static IConfigurationBuilder AddSmartConfig(this IConfigurationBuilder builder, string configKey = "DefaultConnection", string path = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return builder.AddProvider(new SmartConfigProvider(builder, configKey, path));
|
|
|
|
|
|
}
|
2025-02-11 23:32:28 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Adds a smart configuration provider with custom configuration options.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="builder">The configuration builder to add to</param>
|
|
|
|
|
|
/// <param name="setupAction">Action to configure the smart configuration options</param>
|
|
|
|
|
|
/// <returns>The configuration builder</returns>
|
2025-02-11 18:46:51 +01:00
|
|
|
|
public static IConfigurationBuilder AddSmartConfig(this IConfigurationBuilder builder, Action<SmartConfigOptions> setupAction)
|
|
|
|
|
|
{
|
|
|
|
|
|
var options = new SmartConfigOptions();
|
|
|
|
|
|
setupAction(options);
|
|
|
|
|
|
|
2025-02-11 23:10:43 +01:00
|
|
|
|
return builder.AddProvider(new SmartConfigProvider(builder, options));
|
2025-02-02 23:13:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|