0

I need to be able to work with DI Container as a "context". That means, in different contexts the same interface should be resolved with different implementations.

Practically, on resolve one container should look for implementations in one set of assamblies, the other container in an other set.

As this should not be totally dynamic, it could be easily configured per container in the configuration file, which can be loaded by name. There would be multiple implementations of the same interface registered with name in the container, so I could do ResolveAll().

Unfortunatelly, the schema of the unity configuration tells me that the element is bound to the whole Unity "runtime" and not to one or the other container.

Is there any other way to achieve this with Unity? Or can anyone suggest an other IoC framework that can do this?

PS1: I know that it sounds a little bit like plugin architecture, but it is not, and I need the power of DI.

PS2: I could try to reference all assamblies on unity level, and narrow the search on container level using just namespaces and type names, but I can not guarantee that those names will remain unique. The only certain thing is the assambly.

Thank you

lysergic-acid
  • 19,570
  • 21
  • 109
  • 218
ZorgoZ
  • 2,974
  • 1
  • 12
  • 34
  • Can you use code instead declarative configuration? – Alexei Levenkov Dec 02 '16 at 17:22
  • Yes and no. I have to load this from some sort of configuration, as its aim is not to change main code if implementations changes. But if there is a way to create an alternate Load extension method that gives the feature I need, than i can try to code it. – ZorgoZ Dec 02 '16 at 18:48
  • You should be able to just get type(s) by interface(s) http://stackoverflow.com/questions/26733/getting-all-types-that-implement-an-interface and register the mapping http://stackoverflow.com/questions/2911539/registertype-with-an-interface-in-unitycontainer in your container. – Alexei Levenkov Dec 02 '16 at 18:54
  • Thank you @AlexeiLevenkov, I have chosen to manually discover them and register. – ZorgoZ Dec 07 '16 at 08:30

0 Answers0