A library to hook Microsoft.Extensions.Configuration on Load to modify settings' value.
Orwel.Configuration.Hook is available on NuGet. You can add the library to your project with Visual Studio NuGet Packages Manager or with the dotnet cli command :
dotnet add package Orwel.Configuration.Hook
The library has the extension method Hook
on IConfigurationBuilder.
The following code demonstrates basic usage :
private static void ApplyHook(IConfigurationBuilder config)
{
config.Hook(Hook);
}
private static string Hook(KeyValuePair<string, string> setting)
{
// Prepare Url in encoded format
if (setting.Key.StartsWith("Urls:"))
return WebUtility.UrlEncode(setting.Value);
// Decrypt secret
if (setting.Key.StartsWith("Secrets:"))
return setting.Value;
// Remove developpements settings
if (setting.Key.StartsWith("OnlyDev:"))
return null;
// Return the raw value
return setting.Value;
}
With ASP.NET Core :
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((host, config) => config.Hook(Hook))
.UseStartup<Startup>();
Anyone and everyone is welcome to contribute. Please take a moment to review the guidelines for contributing.