CreateApplicationBuilder() creates a separate IApplicationBuilder for an endpoint-specific middleware pipeline. Build that mini-pipeline, then associate it with a route through IEndpointRouteBuilder.Map(). section 31.1.5
Map a middleware endpoint
var endpoint = ((IEndpointRouteBuilder)app) .CreateApplicationBuilder() .UseMiddleware<PingPongMiddleware>() .Build(); app.Map("/ping", endpoint); The middleware runs when a request matches /ping. The cast is necessary because WebApplication hides this advanced method.
