Today I want to show resolve the problem with the way the storage of basic information about the forum, eg, name, keywords.
While I was thinking the easiest solution is simply the idea of \u200b\u200bstoring it in a database. After deep thoughts stated that for basic information does not make sense also tie a database so I decided to use the configuration files that are not available on the platform. Given that, and so they are used when creating the site so it does not cause any zwieszonego burden of reading the data.
configuration files
As most of you know the configuration files are divided into sections. At the beginning create a forum for our basic sections which will hold the simplest information. It looks like this:
\u0026lt;mForum Sitetitle = "mForum"But not too much so I decided to mix configurations on the board to move to a separate configuration file. To our team knew about the main web.configu need to insert this line:
MetaKeywords = "Forum, Board, Project,. Net
MetaDescription =" mForum is going to be Fully Implemented forum featured in C # on. NET platform "
MinPasswordLength = "5">
\u0026lt;/ mForum>
\u0026lt;mForum configSource = "mForum.config" />
Settings
Class This class will store information about all the board settings. Nothing special in this class. Variables and objects that will contain data from the configuration file.
public class Settings {Class SettingsConfigurationSection
public Settings (Sitetitle string, string metaKeywords, metaDescription string, int minPasswordLength)
{
Check.Argument.IsNotEmpty (Sitetitle, "Sitetitle");
Check.Argument.IsNotEmpty (metaKeywords, "metaKeywords ");
Check.Argument.IsNotEmpty (metaDescription," metaDescription ");
Check.Argument.IsNotNull (minPasswordLength, "minPasswordLength");
Check.Argument.IsNotNegativeOrZero (minPasswordLength, "minPasswordLength");
Sitetitle = Sitetitle;
MetaKeywords = metaKeywords;
MetaDescription = metaDescription;
} public string
Sitetitle
{get;
internal set;}
...
}
Here we have the facility to be used in direct pulling data from configuration files. Data from the section are binded to this object. The object itself inherits from the class ConfigurationSection. It looks like this: public class
SettingsConfigurationSection: ConfigurationSectionIt consists of static variables that directly pull data from the section. In addition, there is one variable that is set on a permanent basis. This is the section name. Initializing Settings
{private static string
_sectionName = "mForum"
public static string SectionName
{
[DebuggerStepThrough]
get {return
_sectionName;
}
[DebuggerStepThrough]
set {
Check.Argument.IsNotEmpty
(value, "value");
_sectionName = value;}
}
[ConfigurationProperty (Sitetitle ", DefaultValue = "mForum")]
public string SiteTitle
{
[DebuggerStepThrough]
get
{
return (string)this["SiteTitle"];
}
[DebuggerStepThrough]
set
{
this["SiteTitle"] = value;
}
}
[ConfigurationProperty("MetaKeywords", DefaultValue = "")]
public string MetaKeywords
{
[DebuggerStepThrough]
get
{
return (string)this["MetaKeywords"];
}
[DebuggerStepThrough]
set
{this ["MetaKeywords"] = value;}
}
...
}
class takes place during the registration IoC container as all other objects. There is nothing complicated. Feel free to source the exact implementation.
0 comments:
Post a Comment