Skip to content

Common Configuration

Details

NuGet CodeFandango.Common.Configuration

Overview

This package provides basic extensions of the IConfigurationBuilder type to add configuration JSON files from outside the application folder.

AddUserConfigs

public static void AddUserConfigs(this IConfigurationBuilder configBuilder, 
            string applicationName, 
            string configFileName = "config.json",
            bool reloadOnChange = true)

Example:

var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddUserConfigs("appname");

This adds configuration JSON files from outside the application folder. Specifically:

  • Windows
    • %APPDATA%\appname\config.json
    • %COMMONAPPDATA%\appname\config.json
  • Linux
    • ~/.config/appname/config.json
    • /etc/appname/config.json

If any of these files exists, they will be applied in the order shown above.

Note

On Linux, appname is converted to lowercase.

Note

MacOS is not officially supported. If it works, it's not intentional.

Parameters

  • applicationName - the name of the application folder.
  • configFileName - optional. Defaults to config.json
  • reloadOnChange - optional. Defaults to true. Automatically reloads the configuration file if it changes while your application is running.

AddSystemConfigs

public static void AddSystemConfigs(this IConfigurationBuilder configBuilder,
            string applicationName,
            string configFileName = "config.json",
            bool reloadOnChange = true)

Effectively the same as AddUserConfigs, but only looks in the following locations for configuration files:

  • Windows
    • %COMMONAPPDATA%\appname\config.json
  • Linux
    • /etc/appname/config.json