views:

77

answers:

1

Another developer and had this conversation today:

Me: Dependency Injection is cool, lol.

Dennis: What happens when I need an instance of the DoStuff class and the only constructor I have is DoStuff( ISomeInterface interface1, ISomeInterface interface2 ) where the concrete types are completely different?

Me: ...

We use Unity as our preferred container. How would I register that when I need to resolve ISomeInterface that the concrete type can be two different types?

+2  A: 

Take a look at the ParameterOverride class. It allows you to specify parameters by name:

   container.Resolve<IDoStuff>(new ParameterOverrides<DoStuff> { { "interface1", new SomeInterfaceImpl() }, { "interface2", AnotherSomeInterfaceImpl() } });
charoco