开发者

When is using the <appSettings> section preferable to a custom configuration section?

When creating my application's or library's configuration, I generally prefer using a custom configuration section over the <appSettings> 开发者_如何学运维section for the following reasons.

  • Framework serialization to a user-defined configuration object; each config value has an appropriate type
  • Configuration values may be validated against type and value ranges with attributes

Given this, when would I want to use the loose-typed <add/> key/value mechanism of the <appSettings> section? As I recall, application-level configuration in this section can override existing machine-level configuration from machine.config. Is this the only case, or are there other reasons?


It's easier for quick-and-dirty applications.

It's the same reason ASP.NET has things like the magic "Page_Load" method - no explicit wiring, you probably don't use it in an enterprise-y application; it's just there for RAD.


The appSettings tag has a "file" attribute that allows you to redirect your entire appSettings section to an external file. So for example you can have different appSettings instances for different environments: dev.config, qa.config, etc. I'm not sure if you can do that with other configuration sections though.

Example:

<appSettings file="qa.config"/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜