Cinchoo – Configuration framework – SharedEnvironment, part 1

Shared Environment Configuration

In a situation, where you want to keep and maintain configurations for each  environment (DEV, UAT and PROD etc) separately in a centralized location, attach them to your application and/or switch them at run-time, all these can be done using Cinchoo configuration framework. This is the first of the series of articles about SharedEnvironment in this blog.

SharedEnvironment.config file is a xml based configuration file shared by many applications. It contains configuration entries which controls the location of the application configuration locations and optional machines list for each environment etc.

Cinchoo framework discover this file (SharedEnvironments.xml) in the application base directory if not specified explicitly. It can be overridden by couple of ways

  • appFrxSettings – If the shared environment xml file is in a different location, you can specify them at sharedEnvironmentConfigFilePath attribute in App.config file as below
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
	  <configSections>
    		<section name="appFrxSettings" type="Cinchoo.Core.ChoAppFrxSettings, Cinchoo.Core" />
  	</configSections>
	  <appFrxSettings sharedEnvironmentConfigFilePath="" appEnvironment="QA" />
</configuration>
  • Run-Time – In case where SharedEnvironment xml is not in a file or stored in different sources (Database, WebService etc), you can retrieve them and pass it to the framework by subscribing to ChoApplication.GetSharedEnvironmentConfigXml callback. Below is sample
class Program
{
    static void Main(string[] args)
    {
        ChoApplication.GetSharedEnvironmentConfigXml = new Func<string>(() =>
            {
                string xml = null;
                //Go to source and retrieve the xml
                return xml;
            });
    }
}
Now lets walk over the specification of SharedEnvironments.xml file.
<?xml version="1.0"?>
<configuration>
  <sharedEnvironment baseAppSharedConfigDirectory="C:\Config" defaultEnvironment="DEV">
    <environment name="DEV" comment="DEV Environment" appFrxFilePath="DEVConfig" >
      <machine>WNYC12D10101</machine>
      <machine>WNYC12D10102</machine>
      <machine>WNYC12D10103</machine>
      <machine>WNYC12D10104</machine>
    </environment>
    <environment name="PROD" comment="PROD Environment" appFrxFilePath="C:\Config\PROD\TestApp.config.txt" freeze="true" >
      <machine>SNYC12D10101</machine>
      <machine>100.39.191.175</machine>
    </environment>
    <environment name="UAT" comment="UAT Environment" >
      <machine>WNYC1108054621</machine>
      <machine>SNYC*</machine>
    </environment>
  </sharedEnvironment>
</configuration>
  • baseAppSharedConfigDirectory – A configuration directory used by an environment whose appFrxFilePath is not specified or it contains relative file path. In the above sample, the ‘DEV’ environment will create or use the ‘C:\Config\DEV’ directory to consume configuration files. The environment ‘UAT’ uses ‘C:\Config\UAT’ directory to read / store configuration. If not specified, it will be defaulted to application binary base directory.
  • defaultEnvironment – An environment used by the host which is not listed in this xml. In this sample, the ‘DEV’ environment will be used by the host not attached to any environment.
Each environment can be created using ‘environment’ element. In the above sample, we have ‘DEV’, ‘PROD’, and ‘UAT’ environments.
  • name – Name of the environment, mandatory.
  • freeze – true, all the hosts belongs to the environment locked. The applications hosted on these machines are locked to use this environment. By no means, it can be overridden via App.Config file in appFrxSettings/appEnvironment section. False, it can be overridden. Default value is false. Optional.
  • appFrxFilePath – A file / directory path. Either absolute / relative path. In case of relative path, framework resolves the path in relative to ‘baseAppSharedConfigDirectory’ path. In the sample above, for the ‘DEV’ environment, this path resolved to ‘C:\Config\DEVConfig’. If missing/not specified, the path will be the environment ‘Name’ under ‘baseAppSharedConfigDirectory’. In the sample above, the ‘UAT’ environment will resolve this path to ‘C:\Config\UAT’. It is optional.
Then you can bind hosts to any environment using ‘machine’ element under ‘environment’. Host can be either MachineName or IP Address. Also the those host names can contain wild card characters as well.
Ex: SYNC*, WNYC1002340? etc
Your application can be configured to use particular environment by specifying at appFrxSettings as below unless it is locked via Freeze attribute
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  	<configSections>
    		<section name="appFrxSettings" type="Cinchoo.Core.ChoAppFrxSettings, Cinchoo.Core" />
  	</configSections>
  	<appFrxSettings appEnvironment="QA" />
</configuration>
Advertisements

2 thoughts on “Cinchoo – Configuration framework – SharedEnvironment, part 1

    1. There seems to be a bug in it. Framework expects ‘comment’ attribute value for each environment in the xml file. Will make a fix on the next release as optional value.

      <?xml version="1.0"?>
      <configuration>
        <sharedEnvironment defaultEnvironment="DEV">
          <environment name="DEV" comment="DEV Environment" >
            <machine>WNYC12D10101</machine>
          </environment>
          <environment name="PROD" comment="PROD Environment" >
            <machine>SNYC12D10101</machine>
            <machine>100.39.191.175</machine>
          </environment>
          <environment name="UAT" comment="UAT Environment" >
            <machine>WNYC1108054621</machine>
            <machine>SNYC*</machine>
          </environment>
        </sharedEnvironment>
      </configuration>
      

      Let me know if that works. (Note, the file name of this config file must be SharedEnvironments.xml, not SharedEnvironments.config)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s