New() creates a second ApplicationBuilder , sharing all of the ApplicationServices and ServerFeatures first, but not one of the middleware. It is used internally with extension extensions ( Map , MapWhen , UseWhen ) to create a new "branch".
You can find the implementation here: ApplicationBuilder.cs .
In some cases, it is also useful at a higher level.
For example, the [MiddlewareFilter] attribute in MVC Core uses New() internally to execute part of the core ASP.NET middleware inside the MVC environment (that is, as a filter). MVC Core creates a small pipeline around the middleware, builds it in RequestDelegate, and then runs the HttpContext through it. Like ASP.NET Core, your main pipeline is built in Startup.cs .
With this feature, we can reuse part of the general purpose ASP.NET Core middleware from within MVC.
For more information, see MiddlewareFilterBuilder.cs in ASP.NET MVC Core.
source share