Injection depending on OS, XML configuration

Aug 16, 2011 at 7:38 AM

Hi,

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?

Regards

Aug 16, 2011 at 10:11 AM

Hi,

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 16, 2011 at 11:44 PM

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.