我想了解如何在mvc中調用控制器和操作。 經過大量閱讀後,我發現ExecuteCore()方法得到執行,它存在於Controller.cs類中。ASP.NET MVC中的ExecuteCore()方法
protected override void ExecuteCore()
{
// If code in this method needs to be updated, please also check the BeginExecuteCore() and
// EndExecuteCore() methods of AsyncController to see if that code also must be updated.
PossiblyLoadTempData();
try
{
string actionName = RouteData.GetRequiredString("action");
if (!ActionInvoker.InvokeAction(ControllerContext, actionName))
{
HandleUnknownAction(actionName);
}
}
finally
{
PossiblySaveTempData();
}
}
public IActionInvoker ActionInvoker
{
get
{
if (_actionInvoker == null)
{
_actionInvoker = CreateActionInvoker();
}
return _actionInvoker;
}
set { _actionInvoker = value; }
}
protected virtual IActionInvoker CreateActionInvoker()
{
// Controller supports asynchronous operations by default.
return Resolver.GetService<IAsyncActionInvoker>() ?? Resolver.GetService<IActionInvoker>() ?? new AsyncControllerActionInvoker();
}
當ExecuteCore()開始執行時,對ActionInvoker屬性的引用將其返回給IActionInvoker類型。
IActionInvoker由AsyncControllerActionInvoker.cs類實現,該類中實現了InvokeAction(ControllerContext,actionName)方法。
所以我的問題是:
- 如何IActionInvoker接口被實例化在這裏,和ActionInvoker屬性返回?
- 對屬性的引用是否返回AsyncControllerActionInvoker類的對象,以便我們可以使用該對象調用InvokeAction(ControllerContext,actionName)方法。
Resolver.GetService<IAsyncActionInvoker>()
和Resolver.GetService<IActionInvoker>()
做什麼?
請幫我理解這一點。
很多很多感謝,對我理解這個話題非常有幫助。你能否告訴我一些鏈接,我可以從這裏瞭解更多關於這個主題的內容,以及關於構建在依賴注入中的ASP.NET? – Bibhu 2013-05-09 11:56:04