【发布时间】:2009-09-15 13:08:10
【问题描述】:
我正在将 Castle/Monorails 应用程序转换为 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支持Array但不支持Dictionary,我想做这样的事情:
<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>
我怎样才能实现这样的目标?
【问题讨论】:
-
我有这样的工作。见 - stackoverflow.com/questions/5597492/…
-
这是我针对旧版本的解决方案 - 它需要对代码进行一些更改 - 当我有时间时,也许我会尝试将其适应新版本的 Unity unity.codeplex.com/discussions/230927
标签: c# asp.net unity-container castle-monorail