mvc でコントローラーとアクションがどのように呼び出されるかを理解しようとしています。いろいろ読んだ後、Controller.cs クラス内にある 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 は、InvokeAction(ControllerContext, actionName) メソッドが実装されている AsyncControllerActionInvoker.cs クラスによって実装されます。
だから私の質問は:
- ここで IActionInvoker インターフェイスがどのようにインスタンス化され、ActionInvoker プロパティによって返されるのか?
- プロパティへの参照は AsyncControllerActionInvoker クラスのオブジェクトを返すので、そのオブジェクトを使用して InvokeAction(ControllerContext, actionName) メソッドを呼び出すことができます。
- と は何
Resolver.GetService<IAsyncActionInvoker>()
をResolver.GetService<IActionInvoker>()
しますか?
これを理解するのを手伝ってください。