Roadmap › Design Patterns (GoF + Enterprise) in C# › Module: Behavioural Patterns
Lessons in this course (18)

12. Chain of Responsibility (and ASP.NET Core middleware)

Intermediate★ Must knowLesson 12 of 18

Pass a request along a chain of handlers; each handles it or passes it on.

csharp
app.Use(async (context, next) =>
{
    var sw = Stopwatch.StartNew();
    await next(context);                         // pass to the next handler
    context.Response.Headers["X-Elapsed-Ms"] = sw.ElapsedMilliseconds.ToString();
});
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();

Other examples: HttpClient DelegatingHandler pipeline, MediatR pipeline behaviours, approval workflows (Team Lead → Manager → Director by amount).