Central Config - Multi-Machine .net Configuration Manager

Posted on December 15, 2015

CentralConfig is available on NuGet, source at https://github.com/andrevdm/CentralConfig

Overview

CentralConfig is a replacement for the built in .net ConfigurationManager. It makes managing multi-machine configurations simple while, from a usability point of view, looking very similar to ConfigurationManager.

Features

What about the .net config transformer

The .net transformer does a reasonable job but did not quite do everything I required. The examples below should show some of the differences

Using CentralConfig

Install “CentralConfig” from nuget Unless you have created a custom persistor use the mongo settings persistor Set the central config mongo settings Setup DI

app.settings for the mongo persistor

DI setup

Configure settings in Mongo

Use the setting from code

Different Persistors

I’ve always used the mongo persistor but you can easily create new persistors as required. To do so implement the IPersistor interface

Order of matching

When you request a value, CentralConfig will try find the most specific value it can. So it will first look for the setting match both the key and the current machine name, if that does not match then it looks for a value matching on key only

Given the mongo settings above when you request “TestSetting” you will get “another value” if your machine name is MYPC or “some value otherwise”