本章建立 DelegatorChannel:在主控台列印追蹤訊息,示範通道生命週期與方法呼叫順序。核心設計——委派模式:通道執行特定工作後,將呼叫委派給堆疊下一個通道。完整代碼需第 8 章 Binding 串聯才能執行。
ChannelBase,泛型 TShape : class, IChannel_innerChannel(下一個通道參考)、_source(追蹤字串前綴)ChannelManagerBase(工廠參考)、innerChannel、source,驗證非 null,設定追蹤前綴InnerChannel 供衍生類別存取GetProperty<T>() 透傳查詢CommunicationObject 狀態機方法(OnOpen、OnClose、OnAbort、OnBeginOpen 等),列印追蹤並委派給 _innerChannelDelegatorChannelBase<TShape>、實作 IInputChannel,TShape : class, IInputChannelBeginReceive、BeginTryReceive、BeginWaitForMessage 等,列印追蹤並委派 InnerChannelDelegatorChannelBase<TShape>、實作 IOutputChannel,TShape : class, IOutputChannelBeginSend、Send、RemoteAddress、Via 等,同樣列印追蹤並委派DelegatorInputChannel<IDuplexChannel>、實作 IDuplexChannelIDuplexChannel = IInputChannel + IOutputChannel,繼承輸入通道基類後,僅需補充實作 IOutputChannel 成員(BeginSend、Send、RemoteAddress、Via)DelegatorDuplexChannel、實作 IDuplexSessionChannel_innerSessionChannel 欄位儲存同一物件的 IDuplexSessionChannel 參考Session 屬性:列印追蹤並回傳 _innerSessionChannel.Session同樣模式可擴充至 IInputSessionChannel、IOutputSessionChannel、IRequestSessionChannel、IReplySessionChannel。