在之前的工作中,我们为各种应用程序提供了多个 XML 文件,并且大部分配置都很相似,但根据环境和执行上下文而有所不同。此配置大部分是第三方服务的用户名和密码。当密码发生更改时,我们必须搜索数十个 XML 文件并进行更改,然后重新部署数十个应用程序。
我使用接口和类型层次结构将所有 XML 配置迁移到对象。这些接口允许我针对通用配置结构进行编码,并获得编译时支持以及使用依赖项注入来解析运行时实例。类型层次结构允许我在基类中定义一次不变的配置,并且仅覆盖不同的实际值。
我认为,对于一个小型应用程序来说,这有点过分了,但对我们来说却是必要的。
In a previous job, we had several XML files for our various apps, and much of the configuration was similar, but varied depending on the environment and execution context. Much of this configuration was usernames and password for third party services. When a password would change, we'd have to scour through dozens of XML files and make the changes, then, re-deploy dozens of apps.
I migrated all of the XML configurations to objects using interfaces and a type hierarchy. The interfaces allowed me to code against a common configuration structure, and get compile time support as well as use dependency injection to resolve the run-time instances. The type hierarchy allowed me to define the non-changing configurations once, in a base class, and only override the actual values that differed.
This would be overkill, I think, for a small app, but was imperative in our case.
发布评论
评论(1)
在之前的工作中,我们为各种应用程序提供了多个 XML 文件,并且大部分配置都很相似,但根据环境和执行上下文而有所不同。此配置大部分是第三方服务的用户名和密码。当密码发生更改时,我们必须搜索数十个 XML 文件并进行更改,然后重新部署数十个应用程序。
我使用接口和类型层次结构将所有 XML 配置迁移到对象。这些接口允许我针对通用配置结构进行编码,并获得编译时支持以及使用依赖项注入来解析运行时实例。类型层次结构允许我在基类中定义一次不变的配置,并且仅覆盖不同的实际值。
我认为,对于一个小型应用程序来说,这有点过分了,但对我们来说却是必要的。
In a previous job, we had several XML files for our various apps, and much of the configuration was similar, but varied depending on the environment and execution context. Much of this configuration was usernames and password for third party services. When a password would change, we'd have to scour through dozens of XML files and make the changes, then, re-deploy dozens of apps.
I migrated all of the XML configurations to objects using interfaces and a type hierarchy. The interfaces allowed me to code against a common configuration structure, and get compile time support as well as use dependency injection to resolve the run-time instances. The type hierarchy allowed me to define the non-changing configurations once, in a base class, and only override the actual values that differed.
This would be overkill, I think, for a small app, but was imperative in our case.