Configure your .Net application via environment variables in a manner where
you're not calling Environment.GetEnvironmentVariable
all over the place.
Install via nuget
PM> Install-Package Environmentalist
Define your configuration via an interface. E.g.,
public interface ITestConfig
{
[FromEnvironment("COOL_DICTIONARY")]
IDictionary<string, string> CoolDictionary { get; }
[FromEnvironment("COOL_PROPERTY")]
string CoolProperty { get; }
}
Here, we're using the FromEnvironment
attribute to tell Environmentalist
which environment variable to use with this property.
Create an instance of your configuration via
var config = Configurator.Create<ITestConfig>(new
{
CoolDictionary = new Dictionary<string, string>(),
CoolProperty = "foo"
}
);
The supplied object serves as a set of defaults if Environmentalist can't find a given variable in the environment. Properties which aren't strings are automatically deserialized from the enviroment as JSON.
Environmentalist doesn't assume anything about how you use your configuration. You can just pop the returned object into your IoC container of choice or wrap it in a singleton or static class if you want to use an API closer to the standard way of doing config.