Merging Configs (WCF and otherwise)

Following up on the WCF config theme. Back in April I wrote a config merger for our CAB application. General scenario was as follows: we had a central “shell” application that was loading “plug-ins” based on a dynamic config file. The shell and the plug-ins were developed by different teams with different release schedules, etc.

Each plug-in wanted to use some app.config features, such as application settings, WCF configuration, etc. It turned out that there is no single rule for merging configs: each node should be treated individually. XML document is a tree, so merging XML documents is naturally does in a recursive fashion. We start merging root nodes: one side is the “main” document and the other is the “mix-in” document. We apply one of the three main strategies:

  • No merge: the node may appear only in main or only in mix-in, but not in both
  • Include both: if the node appears in both main and mix-in, insert the mix-in node after the main node
  • True merge: merge children of the mix-in node into the main node (using no merge, include both, or true merge; different methods may be used on children of different kinds)

There is no universal rule that would determine which method to use: e.g. <appSettings> would use true merge, while its children <add>, <remove>, etc. would use “include both”.

Leave a Reply

Your email address will not be published. Required fields are marked *