Should ConfigurationPropertyCollection be static?

In accordance with this often-mentioned article “Unpacking .NET configuration secrets” , it is recommended to follow this template when implementing ConfigurationSection / ConfigurationElement:

private static ConfigurationPropertyCollection s_properties;
static ExampleSection()
{
        // Predefine properties here
        // Add the properties to s_properties
}

/// Override the Properties collection and return our custom one.
protected override ConfigurationPropertyCollection Properties
{
    get { return s_properties; }
}

But this does not explain why the field s_propertiesshould be static, and the properties are initialized in a static constructor.
In the end, access to it is only through a non-static overridden property Properties...

(I have a complicated set of user management settings, this will greatly simplify things in which the field is s_propertiesNOT static ...)

, - "" ? Configuration***, ?
ConfigurationPropertyCollection ?

+3
1

, s_properties ,

s_properties , you - singleton - . [ .] ConfigurationXXX (ConfigurationManager, ) , AppDomain.

, :

private static ConfigurationPropertyCollection s_properties;
static ExampleSection()
{
        // Predefine properties here
        // Add the properties to s_properties
}

/// Override the Properties collection and return our custom one.
protected override ConfigurationPropertyCollection Properties
{
    get { return s_properties; }
}

, s_properties.

, - "" ?

, .

*** , ?

[Edit: Depends... ConfigurationManager. , , AppSettingsCollection. readonly. .. , static Dictionary<string, ConfigurationPropertyCollection> Properties. , - , .]

[ []]
. [Static] ConfigurationXXX , . , / - . , :

string someValue = ConfigurationManager.AppSettings["SomeKey"];  

ConfigurationManager. , AppDomain, .

, . , , , ConfigurationXXX.

+2

All Articles