配置系统的设计指引? [英] Design guidelines for configuration system?

查看:118
本文介绍了配置系统的设计指引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的大部分节目已经在基于Web的应用程序,虽然我已经做了个人项目的一些桌面应用程序开发。一个反复出现的设计问题一直是如何管理的配置。例如,我们都知道,在ASP.NET web.config中经常被用来保存配置信息,无论是生成或手动配置。

Most of my programming has been in web-based applications, although I have done some desktop application development for personal projects. A recurring design issue has been on how to manage the configuration. For example, we all know that in ASP.NET the web.config is used frequently to hold configuration information, whether it be generated or manually configured.

在我甚至知道设计模式是什么,我会实施什么是本质上是一个Singleton模式。我会写的是,在启动时,会读取配置文件,并存储信息,与任何自动生成的信息,在字段,然后通过某种存取(属性暴露给应用程序的其余一起静态类,获得()方法...)。

Before I even knew what design patterns were, I would implement what would be in essence a Singleton pattern. I'd write a static class that, upon startup, would read the configuration file and store the information, along with any auto-generated information, in fields, which were then exposed to the rest of the application through some kind of accessor (properties, get() methods...).

东西在我的脑海里不断告诉我,这是不是去它的最好方式。所以,我的问题是,是否有任何的设计模式或准则设计的配置系统?当和配置系统应该如何读取配置,以及应该如何公开此信息应用的休息吗?它应该是一个Singleton?我不要求推荐的存储机制(XML数据库VS VS文本文件...),但我感兴趣的一个问题的答案为好。

Something in the back of my mind keeps telling me that this isn't the best way to go about it. So, my question is, are there any design patterns or guidelines for designing a configuration system? When and how should the configuration system read the configuration, and how should it expose this information to the rest of the application? Should it be a Singleton? I'm not asking for recommended storage mechanisms (XML vs database vs text file...), although I am interested in an answer to that as well.

推荐答案

不是听起来像一个警察出来,但它真的要完全取决于你的应用程序。非常简单的应用程序(听起来像你讲的基于Web的应用程序,所以我会跳过胖客户端),通常需要无非全局配置更多的(可以使用的web.config并为单身)和每用户配置(用户表,并可能链接的配置表或名称/值对表就可以搞定。

Not to sound like a cop out, but it's really going to completely depend on your app. Very simple apps (sounds like your talking about Web based apps so I'll skip fat clients), usually need nothing more than global config (you can use web.config and a singleton for that) and a per user config (a user table, and possibly a linked config table or name/value pair table can handle that.

更复杂的应用程序可能需要配置这是受保护和可重写的一个完整的层次。例如,我可能有几个应用程序定义的默认值,可以覆盖该用户所属各组,即不能由用户覆盖用户自己终于管理员定义的值特定组或用户。

More sophisticated apps might need a full hierarchy of configuration that's protectable and overridable. For instance, I might have several app defined defaults, that can be overridden for each group that a user belongs to, the user themselves and finally an administrator defined value for a specific group or user that can't be override by the user.

对于这一点,我一般使用有暴露在每个级别的层次结构和配置属性的其他级别的方法一个单身根配置对象。根负责解决层级结构中,但如果有必要(设置例如配置),您可以遍历层次结构自己来处理特定于层次结构单一级别设置。

For that, I generally use a singleton "root config" object that has methods that expose additional levels of the hierarchy and config properties at each level. The root is responsible for resolving the heirarchy , but if necessary (for setting config for instance) you can traverse the heirarchy yourself to deal with settings specific to a single level in the heirarchy.

最后,有延迟的问题。如果您希望配置设置经常改变,从存储每个他们要求的时间去阅读这些是最好的,但最昂贵的。

And finally, there's the issue of latency. If you expect config settings to change often, reading them from storage each time they're requested is best, but most expensive.

如果没有,你可以缓存设置,以最后一次读的日期以来,并简单地重读到期时间后设定值到缓存中。

If not, you can cache settings, along with a "last read" date, and simply reread setting values into the cache after an expiry time.

这篇关于配置系统的设计指引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆