首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> .NET 網頁程式設計 >> ASP.NET 基礎 >> 關於ASP.NET

ASP.NET MVC 同步與非同步五大組件解析 (下)

     編輯:關於ASP.NET

接續上篇,本文探討剩餘兩個組件:ControllerDescriptor 與 ActionDescriptor 的同步/非同步特性,五大組件執行方式有嚴格對應關係。

ControllerDescriptor 同步與非同步

  • ReflectedControllerDescriptor:同步版本,由 ControllerActionInvoker 建立
  • ReflectedAsyncControllerDescriptor:非同步版本,由 AsyncControllerActionInvoker 建立

兩者描述的皆為繼承自 Controller 或 AsyncController 的類別,而非直接實作介面。

ActionInvoker 與 ControllerDescriptor 關係圖

實例驗證

自訂兩種 ActionInvoker 並覆寫 GetControllerDescriptor,搭配繼承 Controller 的 FooController 與 BarController,在 Action 中輸出 Descriptor 類型,證實對應關係。

public class FooController : Controller
{
    protected override IActionInvoker CreateActionInvoker() { return new FooActionInvoker(); }
    public void Index()
    {
        var cd = ((FooActionInvoker)this.ActionInvoker).GetControllerDescriptor(ControllerContext);
        Response.Write(cd.GetType().FullName);
    }
}
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved