Resolving a constructor with two arguments of the same interface?
Another developer and had this conversation today:
Me: Dependency Injection is cool, lol.
开发者_StackOverflow社区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?
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() } });
精彩评论