using System; using System.Configuration; using Sample.Common.Exception; using Microsoft.Practices.EnterpriseLibrary.Common.Configuration; namespace Sample.Config { public sealed class ApplicationSettings { #region Static Members private static readonly ApplicationSettings instance; #endregion Static Members #region Class Members private readonly string settingsPath; private FileConfigurationSource fileConfigurationSource; #endregion Class Members #region Constructors static ApplicationSettings() { instance = new ApplicationSettings(); } private ApplicationSettings() { settingsPath = AppDomain.CurrentDomain.BaseDirectory + "App.config"; fileConfigurationSource = new FileConfigurationSource(settingsPath); fileConfigurationSource.AddSectionChangeHandler("appSettings", this.ApplicationSettings_SectionChanged); } #endregion Constructors #region Properties public static string DataAccessLayerAssembly { get { return ApplicationSettings.GetConfigurationString("DataAccessLayerAssembly"); } } public static string DataAccessLayerNamecpace { get { return ApplicationSettings.GetConfigurationString("DataAccessLayerNamecpace"); } } public static string DatabaseConnection { get { return ApplicationSettings.GetConfigurationString("DatabaseConnection"); } } #endregion Properties #region Handlers private void ApplicationSettings_SectionChanged(object sender, ConfigurationChangedEventArgs e) { #warning fill ApplicationSettings_SectionChanged } #endregion Handlers #region Helper Methods private static string GetConfigurationString(string key) { AppSettingsSection section = instance.fileConfigurationSource.GetSection("appSettings") as AppSettingsSection; if (section != null) { return section.Settings[key].Value; } throw new InvalidCastException("AppSettingsSection"); } #endregion Helper Methods } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)