views:

86

answers:

1

Hello,


I've just started learning about extending the Configuration file structure by creating custom section types ( using ConfigurationSection class ), but I'm not sure I understand its usefulness.

BTW – this is not a »custom section type vs appSettings« question. I already understand the benefits of using custom section types over appSettings element


A) As far as I know, we should implement custom section ( or appSettings element ) whenever we'd like to hard-code particular piece of information ( this information may on rare occasions change). Without the use of custom section type we would have to hard-code that piece information into code, but that would mean that whenever information changes, we'd have to recompile the code.

Is that the only reason for using custom section types ( or appSettings ) or are there other reasons also?


B) Is there a situationatio where, instead of creating custom section type, it would be better to save a particular piece of information ( which hardly ever changes ) into DB or code?


thanx

+2  A: 

One major benefit of using custom config sections that you haven't mentioned yet is type-safety.

In your own custom config section, you can specify the data type for your settings - int, string, DateTime, enumerations - while if you have everything in <appSettings><add key="blabla" value="something" /></appSettings>, you're basically always just dealing with strings.

To me, that's a pretty big and important plus side which makes using custom config sections quite compelling.

Marc

marc_s
You're talking about why'd we prefer to use custom section over appSettings, but I'm more interested in when we should use custom section and when we should find some other means to store information(storing it into DB, or into code or...)
SourceC
OK, well, I guess the basic idea of .NET is to generally use the XML-based config files over anything else and if you do that, you're best of creating your own custom sections for that. At the same time, I am also currently using a hybrid .NET config file / config in database table approach for a variety of reasons.
marc_s
I guess the most compelling argument for the .NET config files is that it is the "officially mandated" way of doing things and everyone in the .NET space should be familiar with and have no trouble grasping what's going on. "Do as the Romans do".
marc_s
But why is using Net config files prefered over anythig else, including storing data into DB ( assuming this data rarely changes )?
SourceC
OK - so how would you store a database connection string in the database? How would you **read** that database connection string?
marc_s
I'm not sure, but I assume it would require a lot more of work than using custom configuration section
SourceC