简体   繁体   English

温莎城堡:注入NameValueCollection vs. Dictionary

[英]Castle Windsor: Inject NameValueCollection vs. Dictionary

I've already done many configs where dictionaries are passed into services in the <parameters> block. 我已经做了很多配置,将字典传递到<parameters>块中的服务中。

But what I find myself needing right now is to build a NameValueCollection (allowing multiple entries with the same key) or a Collection of KeyValuePair objects. 但是我现在发现自己需要构建一个NameValueCollection (允许使用相同的键输入多个条目)或KeyValuePair对象的Collection。

The reason for this is im not using this dictionary to look up b when given a , im basically using it to pass in a Tuple (pair) of (a,b) to be used later in code. 这样做的原因是,在给定a ,我不使用该字典来查找b ,我基本上是使用它来传递(a,b)的元组(对),以便稍后在代码中使用。

Im kind of new to castle windor and I was wondering how i would go about making a List of KeyValuePair 's injected, or a NameValueCollection injected. 我对Castle Windor还是有点陌生​​,我想知道如何处理注入的KeyValuePair列表或注入的NameValueCollection

What i need is something that looks like this: 我需要的是看起来像这样的东西:

<component
    id="Shipper.Air"
    service="CheckoutSystem.Shipping.IShipper, Components"
    type="CheckoutSystem.Shipping.ConditionalShipper, Components">
    <parameters>
      <id>8AED4A27-B5C2-46ad-BEDE-58DCB38F60DA</id>
      <MustSatisfy>True</MustSatisfy>
      <Shippers>
        <dictionary>
          <item key="Ups">${Shipper.UpsAir}</item>
          <item key="CanadaPost">${Shipper.CanadaPostAir}</item>
        </dictionary>
      </Shippers>
      <Conditions>
        <NameValueCollection> <!-- START Example -->
          <item key="Ups">$(ShipperCondition.HeavyItems}</item>
          <item key="CanadaPost">${ShipperCondition.FarNorth}</item>
          <item key="Ups">${ShipperCondition.Default}</item>
        </NameValueCollection> <!-- END Example -->
      </Conditions>
    </parameters>
  </component>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM