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
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