Pipeline
Middleware variant with next() — the ASP.NET Core model.
#When to use it
When steps can decorate the next one: execute before, after, or short-circuit.
var pipe = new AsyncPipeline<HttpContext>()
.Use(async (ctx, next) => { /* logging IN */ await next(); /* logging OUT */ })
.Use(async (ctx, next) => { if (!ctx.IsAuthenticated) return; await next(); })
.Use(async (ctx, next) => { ctx.Response.WriteAsync("OK"); await next(); });
await pipe.RunAsync(httpContext);Tradeoffs
| Pro | Con |
|---|---|
| Allows wrapping – not just chaining | Harder to reason about the order |
#pipeline #middleware