Getting started - eaardal/konfiggy GitHub Wiki
The key component to Konfiggy is the Environment Tag, a simple string that can be resolved in various ways. It's a simple identifier of the current environment the application is running in (such as "dev", "test", "production"). For each of the different machines your server is running on, the environment tag would hold a different value. On your QA server its value could be "QA", on your production server its value could be "prod". The value of the string can be whatever you choose, as long as it matches the prefixes in your app/web.config. What prefixes do you ask?
Let's use this imaginary app settings section:
<appSettings>
<add key="MySetting" value="Dev-server-path" />
<add key="MySetting" value="QA-server-path" />
<add key="MySetting" value="Prod-server-path" />
</appSettings>
Let's add those prefixes to each key:
<appSettings>
<add key="Dev.MySetting" value="Dev-server-path" />
<add key="QA.MySetting" value="QA-server-path" />
<add key="Prod.MySetting" value="Prod-server-path" />
</appSettings>
The prefixes can be whatever you'd like, the above are just the ones I'm most familiar with at my company. However, the separator between the prefix and the key name must be a dot (" . ")!
The Environment Tag then is a string matching a prefix above (Dev, QA or Prod) which Konfiggy will use to get the correct version of MySetting depending on the environment it's running in.
Using Konfiggy looks like this:
- In your start-up logic, set up Konfiggy with how to retrieve the environment tag. (See the "Setting up Konfiggy" page for specifics). The default method is using no environment tag (
NoEnvironmentTagStrategy
)
IKonfiggy konfiggy = new Konfiggy();
// Alternatively set up other methods of resolving the environment tag:
// konfiggy.EnvironmentTagStrategy = new ConfigFileTagStrategy();
// konfiggy.EnvironmentTagStrategy = new CodeTagStrategy();
// konfiggy.EnvironmentTagStrategy = new EnvironmentVariableTagStrategy();
// konfiggy.EnvironmentTagStrategy = new MachineNameTagStrategy();
// konfiggy.EnvironmentTagStrategy = new TextFileTagStrategy();
// konfiggy.EnvironmentTagStrategy = new NoEnvironmentTagStrategy();
// Register with IoC...
All tag strategies are explained elsewhere on this wiki.
- Use Konfiggy:
IKonfiggy konfiggy = new Konfiggy(); // Or resolve from IoC...
string value = konfiggy.GetAppSetting("MySetting");
This would then first resolve the current Environment Tag (such as "dev", "qa" or "prod") and then look for an app setting entry in the config file named <environment tag>.MySetting (such as "QA.MySetting").
For all methods of resolving the environment tag, look at the various "Getting the environment tag using X" pages in this wiki.