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.
PM> Install-Package HumbleConfig
PM> Install-Package HumbleConfig.ConfigurationManager
PM> Install-Package HumbleConfig.EnvironmentVariables
PM> Install-Package HumbleConfig.ConfigR
PM> Install-Package HumbleConfig.MongoDb
First, create an Configuration
instance:
var configuration = new Configuration();
Then, configure the sources for configuration:
configuration.AddEnvironmentVariables()
.AddConfigurationManager()
.AddConfigR()
.AddMongoDb("mongodb://localhost/settings", "appSettings");
We can also 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");
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.
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:")
- Fork
- Hack!
- Pull Request.