Wiki

Clone wiki

MyConfig / Home

MyConfig

Sane-ish Configuration Management

MyConfig is a replacement for .NET's ConfigurationManager. Rather than rely on a AppSettings properties, MyConfig will populate a Plain Old C# Object (POCO) from a source. This source can be App.config, a XML file, a database, or you can create your own plugin.

Right now we only support retrieving settings from App.config

Benefits/Drawbacks

Benefits:

  • Settings are strongly typed rather than relying on a string
  • Settings that are declared but not defined (because a teammate added a new setting but didn't tell you) will raise an exception when settings are loaded
  • You can store your settings outside AppSettings.config

Drawbacks:

  • Only support App.config
  • Can't handle data types like arrays
  • No way to specify default values

Quickstart

  • Add a reference to MyConfig and the plugin you are using as the source
  • Create a POCO object that contains only getter/setter properties. You can use strings, datetime, ints, or anything that supports IConvertible :
    #!c#
    class MySettings {
        public string MaxBackgroundThreads { get; set; }
    }
    
  • Grab your settings!
    #!c#
    var manager = new ConfigurationManager<ConfigurationSettings>(MyConfig.Plugins.AppSettingsConfigProvider.ASSEMBLY_NAME);
    var settings = manager.GetSettings();
    

Updated