輕量級行程,單一 Windows Process 可容納多個 AppDomain。優勢:建立資源少、共享 CLR/基本型別/位址空間/執行緒。獨立性:可獨立卸載、無法互存取組件物件、獨立異常管理/安全性原則/組件解析規則。
AppDomain 可包含多個 Context。所有物件存在於某個 Context,每個 AppDomain 至少有一個預設 Context。ContextBoundObject 衍生類實例為「內容繫結」,永遠在其 Context 執行;非繼承類為「內容靈活」,在呼叫者 Context 執行。
四大介面注入 IMessageSink 至四大區域:
IContributeServerContextSink:服務區 (攔截所有進入目標 Context 物件的呼叫)IContributeObjectSink:物件區 (攔截特定物件)IContributeEnvoySink:信使區 (位於呼叫端 Context,傳遞呼叫端資訊)IContributeClientContextSink:客戶區 (攔截目標 Context 發出的外部呼叫)
ContextAttribute:套用於 ContextBoundObject,實作 IContextAttribute。IsContextOK 判斷現有 Context 是否適用,否則建立新 Context;GetPropertiesForNewContext 注入 IContextProperty。IContextProperty:內容屬性,Freeze 鎖定後不可再注入,IsNewContextOK 驗證新 Context。物件可透過 Context.GetProperty 存取屬性共享資訊。主要作用:向訊息接收器區域注入 Sink。
目標 Context 包含 OBJ1、OBJ2。每個區域可含零至多自訂 Sink,末端皆有系統終結器 Sink。呼叫端與目標端同 AppDomain 時,Remoting 使用 CrossContextChannel 切換執行緒 Context。