开发者

Is App.Config Old News? Should I be using Settings Files (via the Designer) for configuration?

开发者 https://www.devze.com 2023-04-03 16:42 出处:网络
Every .NET project I\'ve worked on uses an app.config file for its configuration.Fair enough. Today I am asking, \"is there a better way?\"(in the spirit of continual learning of course)

Every .NET project I've worked on uses an app.config file for its configuration. Fair enough.

Today I am asking, "is there a better way?" (in the spirit of continual learning of course)

I guess my specific questions are:

  1. Does it matter either way if I use app.config or settings file?
  2. Are there any scenarios where settings files should not be used e.g web sites where you should use a web.config instead?
  3. Other than not having to edit xml, are there any other benefits g开发者_开发技巧ained by using settings instead of app.config, e.g. its easier to deploy or maintain apps etc.

Clarification: I'll put this question another way: Can I completely ignore app.config files if I want to and keep all the configuration in a settings.cs file and interact with configuration via the designer only?


IMO, the main advantage of settings files is scoping (for client apps at least) - that is, that you can have different values of the same setting for a different user. It also allows you to easily edit and save user-scoped settings. And yes, if you don't like editing XMLs - then settings have the advantage of a designer too :)


I don't think it really matters either way, as long as it works for you.

I wouldn't use settings files in situations where values are going to change after an application has been set up.

I tend to use a mixture of custom settings in the web.config and settings within a database.

Custom settings in the web.config are based on this here http://msdn.microsoft.com/en-us/library/2tw134k3.aspx These settings will be things that are not likely to change once the project has been set up, but allow for you to easily share class libraries with other projects.

The database settings are things that are likely to be updated at times during the project, e.g. email addresses

0

精彩评论

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