我轉換城堡/單軌應用爲Unity/Asp.NET MVC之一, 我被困在試圖將這個組件配置:統一:建立一個字典
<component
id="ComponentBaseConfiguration"
service="MyFakeNamespace.BOL.IConfiguration, MyFakeAppDll"
type="MyFakeNamespace.BOL.ConfigurableConfiguration, MyFakeAppDll">
<parameters>
<!-- Setting Configuration (Dictionary<string,string>)-->
<Config>
<dictionary>
<entry key="localHost">#{LocalHost}</entry>
<entry key="contentHost">#{ContentHost}</entry>
<entry key="virtualDir">#{VirtualDir}</entry>
</dictionary>
</Config>
</parameters>
似乎團結支持數組,但沒有解釋,我願做這樣的事情:
<unity>
<containers>
<container>
<types>
<type name="ComponentBaseConfiguration" type="MyFakeNamespace.BOL.IConfiguration, MyFakeAppDll" mapTo="MyFakeNamespace.BOL.ConfigurableConfiguration, MyFakeAppDll">
<typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration">
<property name="Config" propertyType="System.Collections.Generic.Dictionary`2[[System.String, mscorlib], [System.String, mscorlib]],mscorlib">
<dictionary>
<entry key="localHost">127.0.0.1</keyedValue>
<entry key="contentHost">\\content</keyedValue>
<entry key="virtualDir">/</keyedValue>
</dictionary>
</property>
</typeConfig>
</type>
</types>
</container>
</containers></unity>
如何能夠做到這樣呢?
我有這樣的工作。請參閱 - http://stackoverflow.com/questions/5597492/how-do-i-create-and-populate-a-dictionarystring-object-using-unitys-xml-confi/7901103#7901103 – ScArcher2 2011-10-26 18:52:10
這是我的解決方案版本 - 它需要對代碼進行一些更改 - 當我有時間時,也許我會嘗試將它適應Unity的新版本http://unity.codeplex.com/discussions/230927/ – AdaskoTheBeAsT 2016-05-31 13:11:19