How do I create and populate a Dictionary using Unity's xml configuration?

后端 未结 2 1896
我寻月下人不归
我寻月下人不归 2021-01-23 07:30

How do I create and populate a Dictionary using Unity\'s xml configuration?

I need to create a Dictionary and populate the objects using dependency references in unity.<

相关标签:
2条回答
  • 2021-01-23 07:55

    You would have to create some sort of parsing system.

    You can use the XML system in .Net to parse the XML code and then add it to the dictionary by doing dictionary.Add();

    0 讨论(0)
  • 2021-01-23 07:56

    This works

    <unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
    
        <alias alias="MyStuffObject" type="MyStuffObject, MyStuff"/>
        <!-- dictionary stuff -->
        <alias alias="IDictionaryOfStuff" type="System.Collections.Generic.IDictionary`2[[System.String, mscorlib],[MyStuffObject, MyStuff]], mscorlib"/>
        <alias alias="DictionaryOfStuff" type="System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[MyStuffObject, MyStuff]], mscorlib"/>
    
        <!-- Containers -->
        <container name="Stuff">
    
            <register type="IDictionaryOfStuff" mapTo="DictionaryOfStuff" name="dictionaryOfStuff">
                <constructor />
                <method name="Add">
                    <param name="key" type="System.String" value="Cool_Key"/>
                    <param name="value" type="IClinicalDocumentParser" dependencyName="coolStuffObject"/>
                </method>
            </register>
    
            <register type="MyStuffObject" mapTo="MyStuffObject" name="coolStuffObject" />
        </container>
    </unity>
    
    0 讨论(0)
提交回复
热议问题