5
5
using System . Threading . Tasks ;
6
6
using Microsoft . AspNetCore . Builder ;
7
7
using Microsoft . AspNetCore . Hosting ;
8
+ using Microsoft . AspNetCore . Http ;
8
9
using Microsoft . AspNetCore . Mvc ;
9
10
using Microsoft . AspNetCore . Mvc . Abstractions ;
10
11
using Microsoft . AspNetCore . Mvc . Controllers ;
@@ -45,15 +46,20 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
45
46
{
46
47
var routeData = new RouteData ( ) ;
47
48
routeData . Values . Add ( "message" , "Hello World!" ) ;
48
- var actionDesciptor = CreateActionDescriptor < HomeController > ( nameof ( HomeController . Index ) , routeData ) ;
49
- var actionContext = new ActionContext ( context , routeData , actionDesciptor ) ;
50
- var actionInvokerFactory = app . ApplicationServices . GetRequiredService < IActionInvokerFactory > ( ) ;
51
- var invoker = actionInvokerFactory . CreateInvoker ( actionContext ) ;
52
- await invoker . InvokeAsync ( ) ;
49
+ await DriveControllerAction ( context , routeData , app ) ;
53
50
} ) ;
54
51
} ) ;
55
52
}
56
53
54
+ private async Task DriveControllerAction ( HttpContext context , RouteData routeData , IApplicationBuilder app )
55
+ {
56
+ var actionDesciptor = CreateActionDescriptor < HomeController > ( nameof ( HomeController . Index ) , routeData ) ;
57
+ var actionContext = new ActionContext ( context , routeData , actionDesciptor ) ;
58
+ var actionInvokerFactory = app . ApplicationServices . GetRequiredService < IActionInvokerFactory > ( ) ; //ActionInvokerFactory
59
+ var invoker = actionInvokerFactory . CreateInvoker ( actionContext ) ; //ControllerActionInvoker
60
+ await invoker . InvokeAsync ( ) ;
61
+ }
62
+
57
63
private static ActionDescriptor CreateActionDescriptor < TController > (
58
64
string actionName , RouteData routeData )
59
65
{
@@ -79,6 +85,7 @@ private static ActionDescriptor CreateActionDescriptor<TController>(
79
85
routeData . Values . Add ( "controller" , actionDesciptor . ControllerName . Replace ( "Controller" , "" ) ) ;
80
86
routeData . Values . Add ( "action" , actionDesciptor . ActionName ) ;
81
87
88
+ //For binding action parameters
82
89
foreach ( var routeValue in routeData . Values )
83
90
{
84
91
var parameter = new ParameterDescriptor ( ) ;
0 commit comments