.net - Configuration file reading. Best practice -


The application stores the configuration data in the custom section of the configuration file. This information is used on all applications. [XmlRoot ("website site")] Public class WebSiteConfig: IConfigurationSectionHandler {Get public static website configuration turned ON (if (_current == zero) _current = (WebSiteConfig) Configuration Manager. GetSection ("WebSiteSection"); return _current;}} [XmlElement ("section 1")] Public Section 1 Section 1 {Receive; Set;} [XmlElement ("section2")] Public Section 2 Section 2 {Set; ;} ... Create Public Objects (Object Parent, Object Conflict Context, XML Anode section) {var serializer = New XML CERTILIZER (typef (website config)) Return serializer. Dérérialise (new XML reader (section));}}

Then I use it like this

  & lt;%: WebSiteConfig.Current.Section1.Value1% & gt; & lt;%: WebSiteConfig.Current.Section1.Value2% & gt;  

What do you think about it? I find it usable because it makes code easier, but also gets confused as IConfigurationSectionHandler Because the .NET Framework 2.0

OK, in the principal, I have nothing wrong with this concept I see.

A more consistent implementation may be to apply and use a default static example accelerator in your configuration section.


Comments