开发者

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() } });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜