cSharpDirective cSharpDirective - 22 days ago 4x
ASP.NET (C#) Question

how datatype of input parameter of anonymous method determined

I am learning ASP.NET core and in the Startup.cs file I see the context object being referred to write the response as shown below:

enter image description here

I want to know how the input parameter "context" data type is determined?

Please make me understand how the context object is instantiated.


The Run method is an extension method for Microsoft.AspNetCore.Builder.IApplicationBuilder defined in the class RunExtensions. It has the following signature:

Run(Microsoft.AspNetCore.Builder.IApplicationBuilder, Microsoft.AspNetCore.Http.RequestDelegate)

This means that it expects a Microsoft.AspNetCore.Http.RequestDelegate as parameter. Now that delegate is defined as follows:

public delegate Task RequestDelegate(HttpContext context);

Ergo, your context variable must be of type HttpContext.