Click here to Skip to main content
Click here to Skip to main content

Cinchoo - Simplified Configuration Manager

, 27 Jun 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
Easy configuration management in .NET

Introduction

Cinchoo is the application framework for .NET. One of the main functionalities it provides to the users is application configuration management. Application configuration is the information that application reads and/or writes at run-time from the source.

Cinchoo framework simplifies the development with less code and read/write configuration values to the underlying data sources seamlessly. Also, it gives you the flexibility of interchanging the configuration sources through configuration without any code change.

Cinchoo configuration framework has the following powerful features:

  • One single API to deal with configuration data with multiple sources
  • Two-way, type-safe configuration management
  • Create the configuration files, if those are missing
  • Generate the configuration sections, if it does not exist
  • During application run time, has the flexibility of changing the configuration sources without any restart or downtime needed
  • Auto correct the section if it is missing any entries in the configuration files

In this section, I'll run through with a sample in creating and using configuration object in your application. This is the first of the series of articles. More will follow.

How to Use

  • Download the latest Cinchoo binary here.
  • Open VS.NET 2010 or higher
  • Create a sample VS.NET (.NET Framework 4) Console Application project
  • Add reference to Cinchoo.Core.dll
  • Use the Cinchoo.Core.Configuration namespace
  • Copy and paste the below configuration object:
[ChoNameValueConfigurationSection("appSettings")]
public class AppSettings : ChoConfigurableObject
{
    [ChoPropertyInfo("name", DefaultValue="Tom")]
    public string Name;

    [ChoPropertyInfo("address", DefaultValue = "100, Madison Avenue, New York, NY 10010")]
    public string Address;
} 

All the configuration objects must derive from ChoConfigurableObject class. Also, it must decorate with one of the below attributes depending on the type of configuration section storage you want to use:

  • ChoNameValueConfigurationSection - A file based Name/Value configuration section
  • ChoDictionaryConfigurationSection - A file based Key/Value pair configuration section
  • ChoSingleTagConfigurationSection - A file based Key/Value pair represented in single XML tag
  • ChoStandardAppSettingsConfigurationSection - Read/Write Key/Value pair from <appSettings> section
  • ChoIniConfigurationSection - Read/Write configuration values from INI file
  • ChoRegistryConfigurationSection - Read/Write configuration value from System Registry

Add members to configuration object either as Get/Set Property or non-readonly field. You can optionally decorate them with ChoPropertyInfoAttribute with source name, default value, etc.

Once you have the configuration object defined as above, it is now ready to use in your application. Here is how you can create and use it:

static void Main(string[] args)
{
    AppSettings appSettings = new AppSettings();
    Console.WriteLine(appSettings.ToString());

    //Update the name to 'Raj', see it is updating to source
    appSettings.Name = "Raj";

    ChoConsole.PauseLine();
}  

Now compile this program and run. It will create the section in [appExeName].xml file under bin/Config folder.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="appSettings" type="Cinchoo.Core.Configuration.ChoNameValueSectionHandler, 
       Cinchoo.Core, Version=1.0.1.1, Culture=neutral, PublicKeyToken=b7dacd80ff3e33de" />
  </configSections>
  <appSettings>
    <add key="name" value="Tom" />
    <add key="address" value="100, Madison Avenue, New York, NY 10010" />
  </appSettings>
</configuration> 

It is very simple to work with configuration using Cinchoo framework. Try for yourself. Thanks.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Cinchoo

United States United States
No Biography provided

Comments and Discussions

 
QuestionAttached Example PinmemberJanak Desai18-Jun-13 5:09 
AnswerRe: Attached Example PinmemberCinchoo27-Jun-13 12:26 
AnswerRe: Attached Example PinmemberCinchoo29-Jun-13 7:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1411022.1 | Last Updated 28 Jun 2013
Article Copyright 2012 by Cinchoo
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid