/HumbleConfig

HumbleConfig is a simple abstraction on top of multiple config sources

Primary LanguageC#MIT LicenseMIT

HumbleConfig

Stop writing boiler plate configuration code to pull from different sources.

HumbleConfig allows developers to concentrate on writing the application instead of managing all the configuration locations.

install from nugetdownloads Build status

Installing packages

PM> Install-Package HumbleConfig
PM> Install-Package HumbleConfig.ConfigurationManager
PM> Install-Package HumbleConfig.EnvironmentVariables
PM> Install-Package HumbleConfig.ConfigR
PM> Install-Package HumbleConfig.MongoDb

How to use it?

First, create an Configuration instance:

var configuration = new Configuration();

Then, configure the sources for configuration:

configuration.AddEnvironmentVariables()
             .AddConfigurationManager()
			 .AddConfigR()
			 .AddMongoDb("mongodb://localhost/settings", "appSettings");

The order in which we add the configuration sources will determine which configuration values will take priority, in the above example environment variables will override any configuration values within mongodb.

Now knowing the priority of configuration values, we can add some default values by using a InMemory source:

var defaults = new Dictionary<string, object>() { {"UserName", "Kevin.Smith"} };

configuration.AddInMemory(defaults);

Once we're happy with our configuration we can pull out an app setting:

var value = await configuration.GetAppSettingAysnc<string>("key");

Key formatters

Ever been in config hell where you don't know what key is used where. This is where key formatters comes in useful, HumbleConfig has inbuilt support for a few key formatters.

KeyPrefixer

The key prefixer allows you to specify a prefix that all your config keys should include. For example having a prefix of HumbleConfig: would have the following output:

Key Source Key
Key1 HumbleConfig:Key1
Key2 HumbleConfig:Key2
Key3 HumbleConfig:Key3

To setup this the key prefixer on our configuration object we just call WithKeyPrefixer:

configuration.WithKeyPrefixer("HumbleConfig:")

Contributing

  1. Fork
  2. Hack!
  3. Pull Request.