castle windsor学习-----XML Inline Parameters 内联参数
生活随笔
收集整理的這篇文章主要介紹了
castle windsor学习-----XML Inline Parameters 内联参数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
當使用XML配置的時候,可能要給組件指定各種各樣的依賴
1。簡單的參數
參數名稱不區分大小寫
<componentid="ping"type="Acme.Crm.Services.PingService, Acme.Crm"><parameters><pingServer>http://acme.org</pingServer><pingInterval>00:00:30</pingInterval><pingRetries>3</pingRetries><pingNotificator>${emailSender}</pingNotificator></parameters> </component>?
簡單的參數是指簡單的類型,如基元類型,Uri,DateTime,TimeSpan,Type,Enum 或者 服務的重寫,這些參數有它們值表達(簡單的名稱標簽)
參數類型怎么匹配呢?
Windsor不要求你指定參數的類型,而是當解析組件的時候,它將試圖通過名稱去匹配組件的依賴,并檢查是否可以將進行轉換
2.復雜的參數
復雜的參數有多個元素組成
例如你想指定如下的參數
[Convertible] public class ServerInfo {private readonly Uri address;public ServerInfo(Uri address){this.address = address;}public Uri Address{get { return address; }}public int Port { get; set; } }?
應該做如下配置
<parameters><pingServerInfo><parameters><address>http://localhost</address><port>80</port></parameters></pingServerInfo> </parameters>?
3。List參數
public class MyComponent {public MyComponent(IEnumerable<Uri> info){Info = info;}public IEnumerable<Uri> Info { get; private set; } } <parameters><info><list><item>http://localhost:80</item><item>http://castleproject.org</item></list></info> </parameters>?
4.數組
<parameters><info><array><item>http://localhost:80</item><item>http://castleproject.org</item></array></info> </parameters>?
5.字典
<parameters><info><dictionary><entry key="local">http://localhost:80</entry><entry key="castle">http://castleproject.org</entry></dictionary></info> </parameters>?
轉載于:https://www.cnblogs.com/lanpingwang/p/6535821.html
總結
以上是生活随笔為你收集整理的castle windsor学习-----XML Inline Parameters 内联参数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C的指针疑惑:C和指针8数组
- 下一篇: Struts(十):OGNL表达式(一)