Net Core Difference between app.UseMiddleware<T>() and app.Use(context, next)

Viewed 2515

Is there any difference between using IApplicationBuilder of TMiddleware and IApplicationBuilder.Use()? In bot cases I can write elegant extension method and finnaly use

app.UseCustomMiddleware()

but I don't know the benefits of both approaches.

1 Answers

In the link,you can find "the app.Run delegates don't receive a next parameter. The first Run delegate is always terminal and terminates the pipeline."

And in the link,app.UseMiddleWare() can receive a next parameter.

app.UseMiddleWare(), Middleware is generally encapsulated in a class so that you can reuse the middleware, but for app.Use(),you put the code directly in Configure( IApplicationBuilder ) so you cannot reuse it.

Related