I have a single interface and this is being used by 2 classes. I am using unity configuration to identify the instance based on the interface.
Now I want to know how should i register these types so that i can call the appropriate implementation based on the single interface itself.
This is how I do it:
var container = new UnityContainer().RegisterType<IAmImplementedMoreThanOnce, Implementation1>("Implementation1")
.RegisterType<IAmImplementedMoreThanOnce, Implementation2>("Implementation2")
.RegisterType<IHaveDependencies1, WithDependenciesImplementation1>(new InjectionConstructor(new ResolvedParameter<IAmImplementedMoreThanOnce>("Implementation1")))
.RegisterType<IHaveDependencies2, WithDependenciesImplementation2>(new InjectionConstructor(new ResolvedParameter<IAmImplementedMoreThanOnce>("Implementation2")));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With