如果更改一個類型Test
的構造函數參數上IList<A>
您可以使用下面的配置:
<configuration>
<configSections>
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration"/>
</configSections>
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<namespace name="System.Collections.Generic" />
<namespace name="ConsoleApplication1" />
<assembly name="ConsoleApplication1" />
<container>
<register type="A" mapTo="B" name="B" />
<register type="A" mapTo="C" name="C" />
<register type="IList`1[[A]]" mapTo="A[]" />
</container>
</unity>
</configuration>
因此,關鍵是要在A[]
地圖IList<A>
界面 - 請參閱this question瞭解詳情。
你的意思是B和C繼承A? –
哎呀!糾正。謝謝。 – Deepak