Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 12th, 2007, 04:31 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 488
Thanks: 2
Thanked 11 Times in 10 Posts
Default A significant step closer to making TBH modular

Hi all,

had a very very minor (major) brinstorm last night thinking about the 'elements' that make the TBH clunky to modularise and kept coming back to the key section that i know has caused me the most 'work' when i've extracted sections to put up here (i.e. the extended forums and search stuff). basically, what has caused the biggest issue has been extracting the entries from the ConfigSection.cs and then getting the user to paste those into his/her own ConfigSection.cs without causing errors by pasting in wrong place etc. well, taking the design to it's logical conclusion, i've now broken out of this single file and created a folder under App_Code\DAL\ called Config. under this folder, i have entries for each 'provider' (i.e. forums, articles etc..) which contain 'partial' classes of the main ConfigSection.cs. basically, here's how this all looks using articles as an example:

ConfigSection.cs (now looks like this, notice that the public class is now called BaseConfigSection and contains a minimum of info):

using System;
using System.Configuration;
using System.Web.Configuration;
using System.Data;

namespace MB.TheBeerHouse
{
    public class BaseConfigSection : ConfigurationSection
    {
        [ConfigurationProperty("defaultConnectionStringName ", DefaultValue = "LocalSqlServer")]
        public string DefaultConnectionStringName
        {
            get { return (string)base["defaultConnectionStringName"]; }
            set { base["defaultConnectionStringName"] = value; }
        }

        [ConfigurationProperty("defaultCacheDuration", DefaultValue = "600")]
        public int DefaultCacheDuration
        {
            get { return (int)base["defaultCacheDuration"]; }
            set { base["defaultCacheDuration"] = value; }
        }
    }
    public class BaseConfigElement : ConfigurationElement
    {
        // any site-wide config settings could go here
    }
}

the new partial class- App_Code\DAL\Config\ArticlesConfig.cs looks like this (notice that we declare it as a partial class and inherit the BaseConfigSection from ConfigSection.cs):

using System;
using System.Configuration;
using System.Web.Configuration;
using System.Data;

namespace MB.TheBeerHouse
{
    public partial class TheBeerHouseSection : BaseConfigSection
    {
        [ConfigurationProperty("articles", IsRequired = true)]
        public ArticlesElement Articles
        {
            get { return (ArticlesElement)base["articles"]; }
        }
    }

    #region articles element configuration
    public class ArticlesElement : BaseConfigElement
    {
        [ConfigurationProperty("connectionStringName")]
        public string ConnectionStringName
        {
            get { return (string)base["connectionStringName"]; }
            set { base["connectionStringName"] = value; }
        }

        public string ConnectionString
        {
         get
            {
                string connStringName = string.IsNullOrEmpty(this.ConnectionStringName) ? Globals.Settings.DefaultConnectionStringName : this.ConnectionStringName;
                return WebConfigurationManager.ConnectionStrings[connStringName].ConnectionString;
            }
        }

        [ConfigurationProperty("providerType", DefaultValue = "MB.TheBeerHouse.DAL.SqlClient.SqlArticlesProvider ")]
        public string ProviderType
        {
            get { return (string)base["providerType"]; }
            set { base["providerType"] = value; }
        }

        [ConfigurationProperty("enableCaching", DefaultValue = "true")]
        public bool EnableCaching
        {
            get { return (bool)base["enableCaching"]; }
            set { base["enableCaching"] = value; }
        }

        [ConfigurationProperty("cacheDuration")]
        public int CacheDuration
        {
            get
            {
                int duration = (int)base["cacheDuration"];
                return duration > 0 ? duration : Globals.Settings.DefaultCacheDuration;
            }
            set { base["cacheDuration"] = value; }
        }
    }
    #endregion
}

now you may say, what's the big deal about all of that?? well, this means that we can now 99% self contain any new modules, so that we can plug 'n' play new functionality from other 'function providers' (as long as this pattern is used). the only minor paste method left to do, is the addition of the provider to the App_Code\DAL\SiteProvider.cs class, which in this case would be:

        public static ArticlesProvider Articles
        {
            get { return ArticlesProvider.Instance; }
        }

I really hope this is clear to all as this is a biggie, just that i prolly haven't explained it as explosively as i could have. i'll upload an example of the structure in a zip later, so that it's easier to visualise.

without going on too far about it, i'd urge others to examine the possibilities here.

[edit] - just thought i'd also mention that a change that i made a while back also, was the addition of folders under DAL called Entity and Provider. under Entity, i store all the entity classes (ArticleDetails.cs, ForumDetails.cs etc..) and under the Provider folder, i store the provider classes (ArticlesProvider.cs, ForumsProvider.cs etc). it doesn't change the functionality as such, but makes for much better organisation.

jimi

http://www.originaltalent.com
__________________
jimi

http://www.originaltalent.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript Window Closer apartmentsabroad Javascript How-To 3 September 19th, 2006 07:15 AM
We Based Database Step By step desireemm SQL Language 1 October 15th, 2005 08:15 PM
VS.NET MODULAR APPROACH 3Moose BOOK: ASP.NET Website Programming Problem-Design-Solution 2 January 16th, 2005 12:20 PM
Step by step installation peter_budo Beginning PHP 0 August 31st, 2004 12:04 PM
Change number of significant digits displayed gurbani XSLT 1 June 25th, 2004 11:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.