Pipeline

Variante middleware con next() — el modelo de ASP.NET Core.

#Cuándo usarla

Cuando los pasos pueden decorar el siguiente: ejecutar antes, después o cortar.

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 Contra
Permite envolver — no solo encadenar Más difícil de razonar el orden

#pipeline #middleware