This project is read-only.

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 missing
  • Generate the configuration sections, if not exists
  • 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

Cinchoo framework provides some configuration section handlers out of the box. Listed below are few of the available configuration section handlers:

  • ChoNameValueConfigurationSection - Provides name/value pair configuration information from a configuration section.
  • ChoDictionaryConfigurationSection - Provides key/value pair configuration information from a configuration section.
  • ChoSingleTagConfigurationSection - Handles configuration sections that are represented by a single XML tag in the configuration file.
  • ChoStandardAppSettingsConfigurationSection - Read/Write Key/Value pair from <appSettings> section
  • ChoIniConfigurationSection - Read/Write configuration values from INI files.
  • ChoRegistryConfigurationSection - Read/Write configuration values from System Registry.
  • ChoDbGenericKeyValueConfigurationSection - Read/Write configuration values from any databases.

This project is a special configuration section handler to read and write values from JSON file. JSON (JavaScript object notation) is a light weight data-interchange format, widely used across industry nowadays. Using this handler now you can consume the configuration values in JSON format.

Example shows how you can do it in your c# project. First define a configuration object class, decorated with ChoJSONConfigurationSection attribute as below.


    [ChoJSONConfigurationSection("appSettings", ConfigFilePath = "test.json")]
    public class AppSettings : ChoConfigurableObject
    {
        [ChoPropertyInfo("name", DefaultValue = "Raj")]
        [ChoNotNullOrWhiteSpaceValidator]
        public string Name
        {
            get;
            set;
        }

        [ChoPropertyInfo("address", DefaultValue = "10 River Road, 08837")]
        public string Address;

        [ChoPropertyInfo("Date", DefaultValue = "%%NOW^MM/dd/yyyy HH:mm:ss%%")]
        public DateTime Date;

        protected override void OnAfterConfigurationObjectLoaded()
        {
            Console.WriteLine(ToString());
        }
    }

Once you have a configuration object defined above, it is relatively simple to consume the values by constructing object out of it.

         static void Main(string[] args)
        {
            AppSettings appSettings = new AppSettings();
            var x = appSettings.Name;

            ChoConsole.PauseLine();
            ChoFramework.Shutdown();
        }

That's all, now the changes made to the object will be stored in the underlying file and also any changes made to the underlying JSON file will be reflected automatically in the object as well. Download the source files and try for yourself. Thanks.

Last edited Aug 17, 2015 at 10:44 PM by Cinchoo, version 5