Skip to content

vernou/Orwel.Configuration.Hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Orwel.Configuration.Hook

Build and Test codecov License: MIT

A library to hook Microsoft.Extensions.Configuration on Load to modify settings' value.

Installation

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

Usage

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>();

Contributing to this project

Anyone and everyone is welcome to contribute. Please take a moment to review the guidelines for contributing.

About

Hook to Microsoft.Extensions.Configuration on Load

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages