Separating a "wad of stuff" utility project into individual components with "optional" dependencies
Posted
by
romkyns
on Programmers
See other posts from Programmers
or by romkyns
Published on 2011-12-15T13:59:24Z
Indexed on
2012/09/18
21:52 UTC
Read the original article
Hit count: 373
Over the years of using C#/.NET for a bunch of in-house projects, we've had one library grow organically into one huge wad of stuff. It's called "Util", and I'm sure many of you have seen one of these beasts in your careers.
Many parts of this library are very much standalone, and could be split up into separate projects (which we'd like to open-source). But there is one major problem that needs to be solved before these can be released as separate libraries. Basically, there are lots and lots of cases of what I might call "optional dependencies" between these libraries.
To explain this better, consider some of the modules that are good candidates to become stand-alone libraries. CommandLineParser
is for parsing command lines. XmlClassify
is for serializing classes to XML. PostBuildCheck
performs checks on the compiled assembly and reports a compilation error if they fail. ConsoleColoredString
is a library for colored string literals. Lingo
is for translating user interfaces.
Each of those libraries can be used completely stand-alone, but if they are used together then there are useful extra features to be had. For example, both CommandLineParser
and XmlClassify
expose post-build checking functionality, which requires PostBuildCheck
. Similarly, the CommandLineParser
allows option documentation to be provided using the colored string literals, requiring ConsoleColoredString
, and it supports translatable documentation via Lingo
.
So the key distinction is that these are optional features. One can use a command line parser with plain, uncolored strings, without translating the documentation or performing any post-build checks. Or one could make the documentation translatable but still uncolored. Or both colored and translatable. Etc.
Looking through this "Util" library, I see that almost all potentially separable libraries have such optional features that tie them to other libraries. If I were to actually require those libraries as dependencies then this wad of stuff isn't really untangled at all: you'd still basically require all the libraries if you want to use just one.
Are there any established approaches to managing such optional dependencies in .NET?
© Programmers or respective owner