App.Config 与自定义 XML 文件

发布于 2024-08-07 22:22:16 字数 246 浏览 2 评论 0原文

我读过很多诸如“你不应该用自定义设置阻塞你的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

生来就爱笑 2024-08-14 22:22:16

以我的拙见,有些人倾向于在自定义配置部分处理程序上有点过分。

我倾向于仅在需要非常结构化的东西时才使用它们;这是由第三方使用/编写的(即我想对其进行一些额外的验证)。

我认为您可以非常愉快地使用 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.

谁与争疯 2024-08-14 22:22:16

查看应用程序设置架构,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.

小耗子 2024-08-14 22:22:16

大多数设置往往属于以下三个阵营之一:

  1. 影响代码内部行为的技术设置,例如数据库连接字符串、数据文件路径、日志记录开关、错误处理开关等。
  2. 影响产品业务逻辑的业务设置,例如“用户是否可以访问 CRM 模块?”
  3. 用户特定的配置文件值,例如“是否允许该用户访问 CRM 模块?”。

类型 1 的自然位置是在 app.configweb.config 中,类型 2 和 3 的自然位置是在数据库中。

Most settings tend to fall into one of three camps:

  1. Technical settings that affect the internal behaviour of the code, e.g. database connection string, data file path, logging switches, error handling switches, etc.
  2. Business settings that affect the business logic of the product, e.g. "are users allowed to access the CRM Module?"
  3. User-specific profile values, e.g. "is this user allowed to access the CRM Module?".

The natural place for type 1 is in app.config or web.config, and the natural place for types 2 and 3 is in the database.

风吹雨成花 2024-08-14 22:22:16

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.

格子衫的從容 2024-08-14 22:22:16

在我看来,我认为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文