Click here to Skip to main content
15,896,421 members
Articles / Programming Languages / XML

netTierGenerator

Rate me:
Please Sign up or sign in to vote.
4.81/5 (20 votes)
30 Nov 2008CPOL14 min read 67.7K   2.8K   108  
A 3-tier application framework and code generation tool - the way for rapid and effective development.
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions