Injection depending on OS, XML configuration

Aug 16, 2011 at 8:38 AM


I'm writing an application which has configuration for Unity in XML file. How should I write my configuration to inject proper ConcreteClass depending on OS Version?


Aug 16, 2011 at 11:11 AM


I doubt that it will be achievable with pure XML Configuration since you can't insert logic into it. I'm thinking more of XML and code combination. My idea is you can declare all the necessary type mappings through XML (named registrations) then in your code, you can check the current OS Version. After that, resolve the appropriate implementation through named registration.


Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
Contact Us

Aug 17, 2011 at 12:44 AM

You'll need to write some code, but it could be at the point where you load the configuration into the container. You can load multiple configuration sections into a single container instance, and last one in wins.

So what you'd do is write your XML and split it up into several "container" elements. The first would be a "baseline" configuration, which contains the configuration that doesn't change from OS to OS. Then you'd have a series of other "container" elements, one per OS version, containing just the configuration for that OS.

Then, when creating and configuration the container, you'd first load the baseline configuration, then write the logic to figure out which OS you're on, then load that OS specific configuration XML as well into the container.