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

Cinchoo - Simplified Configuration Manager

By , 18 Apr 2013
 

Introduction

Cinchoo is the application framework for .NET. One of the main functionality it provides to the users is that 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 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)

About the Author

Cinchoo
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 19 Apr 2013
Article Copyright 2012 by Cinchoo
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid