How to configure Unity from several versions of the same assembly?

I have several build versions, each of which implements the RequestHandler type (with IRequestHandler).

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

At run time, requests are processed by the correct version using an alias to instantiate the correct version of the assembly.

To do this, you need to configure the configuration. I do not know how to configure Unity for this? Any ideas?

+3
source share
1 answer

Easy to configure using the 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; }

}
+4
source

Source: https://habr.com/ru/post/1763363/


All Articles