What is middleware
Middleware
is software that assembled into app pipeline to handle request and responses. Each component
- Chooses whether to pass the request to the next component in the pipeline
- Can perform work before or after the next component in pipeline
Request delegate
used to build the request pipeline. The request delegates handle each HTTP request
In-line middleware
when delegate have been identified as an anonymous method
With individual request the delegate can be specified in-line as an anonymous methods or it can be defined in a reusable class. This reusable class or in-line anonymous methods are middleware, also called middleware components
Each middleware component in the request pipeline is responsible for invoking the next component in the pipeline or short-circuiting the pipeline. When middleware short-circuiting it’s called a terminal middleware because it prevents further middleware from processing request
The Asp.Net core request pipeline consists of sequence of request delegates, called one after the other The following diagram demonstrates the concept
The simplest possible ASP.NET Core app sets up a single request delegate that handles all requests. This case doesn't include an actual request pipeline. Instead, a single anonymous function is called in response to every HTTP reques
public class Startup
{
public void Configure(IApplicationBuilder app)
{
app.Run(async context =>
{
await context.Response.WriteAsync("Hello, World!");
});
}
}