【问题标题】:StructureMap List of Non primitive typesStructureMap 非原始类型列表
【发布时间】:2011-02-05 10:05:15
【问题描述】:

我正在尝试弄清楚如何设置 StructureMap(使用 XML 配置文件)。一个类有一个构造函数,其中包含一个包含第二类实例的列表:

public interface ITestDocType { }

class TestDocType : ITestDocType
{
    public List<AttributeRef> AttrRefs { get; set; }

    public TestDocType(List<AttributeRef> attrRefs)
    {
        AttrRefs = attrRefs;
    }
}

public class AttributeRef
{
    public AttributeRef(string name, string xpath, string value)
    {
        Name = name;
        Xpath = xpath;
        Value = value;
    }

    public string Name { get; set; }
    public string Xpath { get; set; }
    public string Value { get; set; }
}

我希望能够在我的配置文件中内联 AttributeRef 的实例,但不完全确定它是如何完成的(或者如果可能的话)。

<DefaultInstance PluginType="ITestDocType" PluggedType="TestDocType">
    <attrRefs>
       // Would like to specify one to many AttributeRef instances inline here
    </attrRefs>
</DefaultInstance>

【问题讨论】:

    标签: c# structuremap


    【解决方案1】:

    好的..我想通了,它是described pretty nicely in the documentation..我只需要阅读几遍就可以完全理解。

      <DefaultInstance PluginType="yyy" 
                   PluggedType="yyy">
          <attrRefs>
              <Child>
                  <DefaultInstance PluginType="xxx"
                                   PluggedType="xxx"
                                   name="id" x
                                   path="/item/@idd" 
                                   attrValue="none">
                  </DefaultInstance>
              </Child>
          </attrRefs>
      </DefaultInstance>
    

    如您所见,“attrRefs”是采用 List 的构造函数中的参数名称,对于要添加到该列表的每个元素,将 DefaultInstance 元素包装在“Child”元素中。

    【讨论】:

    • 好的,所以这并没有按照它应该的方式工作......当父实例被检索时,“attrRefs”参数包含一个空列表......回到绘图板。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-07
    • 1970-01-01
    • 1970-01-01
    • 2011-08-09
    • 2016-01-21
    相关资源
    最近更新 更多