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