Giter Club home page Giter Club logo

centralconfig's Introduction

CentralConfig - Multi-machine configuration manager

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

  • All config must be able to be stored in version control
  • A way to have config centralised. I.e. you should not have to update the same setting on multiple machines.
  • Support for multiple environments (dev, build, test, prod etc)
  • A sane and simple way of having default values. You should not have to specify the same settings for each machine if a default will work.
  • Override a setting for a particular machine. e.g. one machine in an environment must have a slightly different config.
  • Simple and light weight
  • Support for simple values as well as more complex object types
  • A full replacement for ConfigManager

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 mong persistor

   <appSettings>
     <add key="MongoDB.Server" value="mongodb://localhost:27017" />
     <add key="CentralConfig.MongoDatabase" value="TestConfig" />
   </appSettings>

DI setup

   ObjectFactory.Configure( x =>
   {
       x.For<IEnvironment>().Use<SystemEnvironment>();
       x.For<IConfigPersistor>().Use<MongoDbConfigPersistor>();
   } );

Configure settings in Mongo

   {
       "key" : "TestSetting",
       "machine" : null,
       "value" : "some value"
   }

Use the setting from code

   //ConfigManager.AppSettings["TestSetting"]
   Console.WriteLine( "test: {0}", ConfigManager.AppSettings["TestSetting"] );

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

    public interface IConfigPersistor
    {
        string ReadAppSetting( string key, string machine, long version );
        string ReadAppSetting( string key, string machine );
        string ReadAppSetting( string key, long version );
        string ReadAppSetting( string key );

        TResult GetSection<TResult>( string sectionName, string machine, long version );
        TResult GetSection<TResult>( string sectionName, string machine );
        TResult GetSection<TResult>( string sectionName, long version );
        TResult GetSection<TResult>( string sectionName );
    }

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

   {
       "key" : "TestSetting",
       "machine" : null,
       "value" : "some value"
   },
   {
       "key" : "TestSetting",
       "machine" : "MYPC",
       "value" : "another value"
   }

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

centralconfig's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

pcubed jorik041

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.