views:

21

answers:

1

I have multiple versions of an assembly that each implements a type called RequestHandler (with IRequestHandler).

I want to configure unity each of the versions available using an alias like 'v1.1' or 'v1.2'.

At runtime requests are handled by the correct version using the alias to create an instance of the correct version of the assembly.

This needs to be config driven. I don't know how to configure Unity to acheive this? Any ideas?

+2  A: 

It is easy if configuration is made with configuration file:

<unity>
 <containers>
  <container>
   <type type="IMyInterface" mapTo="myNamespace.MyHandler, MyAssembly, Version=1.1.0.0, Culture=neutral" name="v1.1" />
   <type type="IMyInterface" mapTo="myNamespace.MyHandler, MyAssembly, Version=1.2.0.0, Culture=neutral" name="v1.2" />
  </container
 </containers>
</unity>

And, in the client:

public class MyClient {
   [Dependency("v1.1")]
   public IMyInterface MyVal { get; set; }

}
onof