A common dictionary containing a common dictionary in Spring.Net

I have an object that contains a property:

public Dictionary<string, Dictionary<string, List<ContextMenuItemModel>>> ContextMenuModel { get; set; }

How to use Spring.Net to configure this property?

+3
source share
1 answer

Well, setting this up in xml is pretty small, consider switching to Spring. Configuring code in a format, configure your spring context in C # / a>.

In any case, to do this in xml, you use the .net shared collection constructors. For example, it List<T>takes a constructor IList<T>, so you can customize the list of strings as follows:

<object id="list1" type="System.Collections.Generic.List&lt;string>">
  <constructor-arg>
    <list element-type="string">
      <value>abc</value> 
      <value>def</value> 
    </list>
  </constructor-arg>
</object>

, xml &lt;, < xml. Spring.net docs.

Dictionary<string, System.Collections.Generic.List<string>> , :

<object id="dic1" type="System.Collections.Generic.Dictionary&lt;string, System.Collections.Generic.List&lt;string>>">
  <constructor-arg>
    <dictionary key-type="string" value-type="System.Collections.Generic.List&lt;string>">
      <entry key="keyToList1" value-ref="list1" />
      <entry key="keyToList2" value-ref="list2" /> 
    </dictionary>
  </constructor-arg>
</object>

, , :

<object id="dic0" type="System.Collections.Generic.Dictionary&lt;string, System.Collections.Generic.Dictionary&lt;string, System.Collections.Generic.List&lt;string>>>">
  <constructor-arg>
    <dictionary key-type="string" value-type="System.Collections.Generic.Dictionary&lt;string, System.Collections.Generic.List&lt;string>>">
      <entry key="keyToDic1 " value-ref="dic1" />
    </dictionary>
  </constructor-arg>  
</object>

:

<object id="MyObject" type="MyNamespace.MyClass, MyAssembly">
  <property name="ContextMenuModel" ref="dic0" />
</object>

, xml .

+5

All Articles