35 lines
1.7 KiB
C#
35 lines
1.7 KiB
C#
using PlanTempus.Core.Configurations;
|
|
|
|
namespace PlanTempus.Core.Configurations.SmartConfigProvider
|
|
{
|
|
/// <summary>
|
|
/// Extension methods for adding smart configuration providers to IConfigurationBuilder.
|
|
/// </summary>
|
|
public static class SmartConfigExtension
|
|
{
|
|
/// <summary>
|
|
/// Adds a smart configuration provider using a connection string from appsettings.
|
|
/// </summary>
|
|
/// <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>
|
|
public static IConfigurationBuilder AddSmartConfig(this IConfigurationBuilder builder, string configKey = "DefaultConnection", string path = null)
|
|
{
|
|
return builder.AddProvider(new SmartConfigProvider(builder, configKey, path));
|
|
}
|
|
/// <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>
|
|
public static IConfigurationBuilder AddSmartConfig(this IConfigurationBuilder builder, Action<SmartConfigOptions> setupAction)
|
|
{
|
|
var options = new SmartConfigOptions();
|
|
setupAction(options);
|
|
|
|
return builder.AddProvider(new SmartConfigProvider(builder, options));
|
|
}
|
|
}
|
|
}
|