Antipattern: The Bloated Configuration File

Configuration files should contain only the values the end users will need to configure. Everything else should be in code.

One problem with WCF is the size of the configuration files. They contain so much data they are unreadable. Its such a problem that Microsoft provides the WCF Configuration Editor to ease developers pain when editing them.

This is even more of an issue when users need to edit them. I have user-editable configuration settings in my app.config, but since the  WCF settings also reside in that file there is a risk that users will accidentally change them and cause failure. Not good.

WCF is a good example of a bloated config file, but the problem is not isolated to WCF. Anytime a config file contains non-configurable concerns, it is bloated.

You see, a bloated config file contains 2 types of data:

  1. User-editable configuration settings
  2. Static application configuration (should never change…in my case, this is WCF binding configuration).

This violates SRP. Yes, I know, the Single Responsibility Principle applies to objects/classes, but it often applies beyond that scope as well.  In this case it applies at the file-level. A config file should have one and only one responsibility: user-configurable settings. Anything beyond that introduces confusion and increases risk when editing the file. If the users should never edit the WCF bindings, keep them out of the config file.

So how do we fix it? Configure the WCF bindings in code rather than the config file. Expose only the WCF settings the users should modify as settings in the config file (endpoint addresses, timeouts, etc). Express everything else in code or in another file, safely out of reach. The result is clean config files that users can understand and edit without the fear of changing something they shouldn’t.


This entry was posted in .NET, Configuration, Principles and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>