Choice of configuration settings storage is an important topic when it comes to enterprise BizTalk application planning. One of the many options is to use regular.Net configuration files. Some prefer this way over the Enterprise SSO database option for reasons of simplicity and familiarity. I wanted to show how it can be done with Microsoft Enterprise Library configuration application block.

In this caseEnterprise Library configuration section is placed in theBTNTSvc.exe.config file while application settings are stored in a separate configuration file.The problem here is how do we make EntLibtoload required settings file at runtime. Its done by simple helper class CustomSettingsthat looks up registry entry for the location and name of the application configuration file and creates FileConfigurationSource with it.The registry entrycan becreated by MSI installation package.

The initialization method of this helper class looks like this (thread synchronization code omited for brevity):

          RegistryKey regKey = null;

             regKey = Registry.LocalMachine.OpenSubKey(@"Software\MyCompany\MyApplication");
             configurationFile = Path.Combine(

              ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
              fileMap.ExeConfigFilename = configurationFile;
              configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
              configurationSource = new FileConfigurationSource(configurationFile);

              //- store configPath in the settings
              new KeyValueConfigurationElement("configDir", (string)regKey.GetValue("ConfigDir")));
           catch (Exception ex)
              Debug.WriteLine("Exception while initializing Settings:" + ex.ToString());
              throw ex;
              if (regKey != null) regKey.Close();

Then it has method to access properties by name:

        public static string GetValue(string name)
            KeyValueConfigurationElement entry = Configuration.AppSettings.Settings[name];

            if (entry == null)
                throw new ConfigurationErrorsException("Key '" + name + "' is not found in the configuration file.");

            return Configuration.AppSettings.Settings[name].Value;

Which is used as in:

string propertyValue = CustomSettings.GetValue("propertyName");