C# 使用Key Ref的Spring.NET合并字典
相关的: 我试图在Spring.NET配置中创建合并的父/子继承对象,如下所示:C# 使用Key Ref的Spring.NET合并字典,c#,spring,merge,spring.net,C#,Spring,Merge,Spring.net,相关的: 我试图在Spring.NET配置中创建合并的父/子继承对象,如下所示: <object name=".parent" abstract="true" type="Assembly.KeysAndValues, Assembly"> <property name="TheDictionary"> <dictionary key-type="Assembly.KeyType, Assembly" value-type="Assembly.Value
<object name=".parent" abstract="true" type="Assembly.KeysAndValues, Assembly">
<property name="TheDictionary">
<dictionary key-type="Assembly.KeyType, Assembly" value-type="Assembly.ValueType, Assembly">
<entry key-ref="Object1" value-ref="Value1" />
<entry key-ref="Object2" value-ref="Value2" />
<entry key-ref="Object3" value-ref="Value3" />
</dictionary>
</property>
</object>
<object name="child" parent=".parent">
<property name="TheDictionary">
<dictionary merge="true">
<entry key-ref="Object2"><null/></entry>
</dictionary>
</property>
</object>
spring集合合并是否不支持key ref,或者这里正在进行其他操作?在对spring.NET源代码进行一些调试之后,我为spring.NET Github项目创建了一个pull请求,因为我认为这是库中的一个bug。有了我的零钱,词典合并就成功了。有关问题的详细信息,请参阅拉动请求:
Object2是否在spring容器中定义为singleton?我曾尝试将其标记为singleton,但相同的错误仍然存在,不管key ref对象上是否有该属性。我还尝试在key ref对象类型上实现相等成员,并继续看到错误。
InnerException: System.ArgumentException
HResult=-2147024809
Message=An item with the same key has already been added.
Source=mscorlib
StackTrace:
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at System.Collections.Generic.Dictionary`2.System.Collections.IDictionary.Add(Object key, Object value)
at Spring.Objects.Factory.Config.ManagedDictionary.Resolve(String objectName, IObjectDefinition definition, String propertyName, ManagedCollectionElementResolver resolver)
at Spring.Objects.Factory.Support.ObjectDefinitionValueResolver.ResolvePropertyValue(String name, IObjectDefinition definition, String argumentName, Object argumentValue)
at Spring.Objects.Factory.Support.ObjectDefinitionValueResolver.ResolveValueIfNecessary(String name, IObjectDefinition definition, String argumentName, Object argumentValue)
at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.ApplyPropertyValues(String name, RootObjectDefinition definition, IObjectWrapper wrapper, IPropertyValues properties)
at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.PopulateObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper)
at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper)
at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InstantiateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching, Boolean suppressConfigure)