App.Config 与自定义 XML 文件
我读过很多诸如“你不应该用自定义设置阻塞你的 app.config 文件”之类的陈述。但是,我的印象是这正是该文件的目的?
这确实只是一种偏好吗?或者,与 app.config 文件相比,使用自定义 XML 文件是否有任何真正的好处(除了设置分离之外)?如果您需要显式分隔设置,那么使用自定义 ConfigurationSection
是否会比选择自定义 XML 文件更好?
我想听听其他人对此的想法。
I have read a lot of statements like "you shouldn't clog your app.config file with custom settings". However, I was under the impression that this was exactly the purpose of the file?
Is it just indeed a preference thing? Or are there any real benefits (other than separation of settings) by using a custom XML file, as apposed to the app.config file? If you need to explicitly separate settings would it better to use a custom ConfigurationSection
rather than opting for a custom XML file?
I would like to here other peoples thoughts on this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
以我的拙见,有些人倾向于在自定义配置部分处理程序上有点过分。
我倾向于仅在需要非常结构化的东西时才使用它们;这是由第三方使用/编写的(即我想对其进行一些额外的验证)。
我认为您可以非常愉快地使用 app.config/web.config 进行所有相关设置,并在很清楚这是应用程序的单独组件时使用单独的 XML 文件。
Some people tend to go a bit overboard on custom config section handlers, in my humble opinion.
I tend to use them only when I need something that is very structed; and that is used/written by 3rd parties (i.e. I want to do some extravagent validation on it).
I think you can quite happily use app.config/web.config for all relevant settings, and use separate XML files when it is very clear that is a separate component of the app.
查看应用程序设置架构,app.config 用于关于应用程序的配置,虽然这是一个非常笼统的术语。所以我建议您查看应用程序设置文件。
我不会在 app.config 中存储“启动时加载数据库”之类的设置。我宁愿使用像应用程序设置这样的替代存储,不要将应用程序配置与设置混淆,即使您可能想这样做,但不要这样做。 app.config 应该具有有关较低级别事物的配置,例如数据库连接、成员资格提供程序或任何其他应用程序评论信息。
Have a look at the Application Settings Architecture, the app.config is for Configration regarding the Application, thats quite a general term though.. So I would suggest you look into the Application Settings Files.
I would not store settings like "load database on startup or not" in the app.config. I would rather use an Alternative Storage like Application Settings for this, don't confuse Application Configuration with Settings, even though you might want to do that, Don't. app.config is supposed to have configration regarding lower level things like Database connection, Membership Provider or any other Application Critic information.
大多数设置往往属于以下三个阵营之一:
类型 1 的自然位置是在
app.config
或web.config
中,类型 2 和 3 的自然位置是在数据库中。Most settings tend to fall into one of three camps:
The natural place for type 1 is in
app.config
orweb.config
, and the natural place for types 2 and 3 is in the database.App.Config 适用于特定于应用程序的配置:数据库路径就是一个很好的例子。其余的应该排除在外。
您可能想做的一件事是创建特定于用户的文件,然后您可以使用将保存到isolatedstore 中的自定义xml。
App.Config are good for configuration that are application specific : path to database is a good example. The rest should be out of it.
One thing you might want to do is to create user-specific files, you can then use custom xml that will be saved into an IsolatedStore.
在我看来,我认为 app.config 适合部署时设置,例如数据库的位置、IP 地址或关键数据文件的位置等。用户设置(例如字体、颜色、行为首选项)应该放在您可以使用 Xml 序列化轻松创建和保存不同的文件。
In my opinion I consider app.config to be good for deployment-time settings such as the location of the database, or an IP address or location of critical data file, etc. User settings like font, color, behavior preferences should go in a different file which you can easily create and save with Xml serialization.