middleware-patterns

Explain and demonstrate middleware creation and configuration patterns in ASP.NET Core.

10|Updated Jan 28, 2026
One-click install
npx skills add https://github.com/AGIBuild/Agibuild.Fulora --skill middleware-patterns-agibuild
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: middleware-patterns
Source: https://github.com/AGIBuild/Agibuild.Fulora/tree/main/.cursor/skills/middleware-patterns
Command: npx skills add https://github.com/AGIBuild/Agibuild.Fulora --skill middleware-patterns-agibuild

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides comprehensive guidance on building and managing middleware in ASP.NET Core applications, ensuring efficient and robust request processing pipelines.

Core Features & Use Cases

  • Pipeline Ordering: Understand the critical sequence of middleware registration for correct execution.
  • Middleware Patterns: Learn convention-based, factory-based (IMiddleware), and inline middleware development.
  • Conditional Logic: Implement UseWhen and MapWhen for dynamic pipeline branching.
  • Error Handling: Master built-in and custom exception handling strategies, including IExceptionHandler.
  • Use Case: When developing a new ASP.NET Core API, use this Skill to implement custom authentication middleware, configure request logging, and ensure proper error handling across all endpoints.

Quick Start

Show me how to implement a convention-based middleware that logs the duration of each incoming request.

Frequently Asked Questions about middleware-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I configure ASP.NET Core middleware pipeline ordering correctly?

ASP.NET Core middleware pipeline ordering determines the sequence of request processing, where registered components execute in order and response delegation reverses. Correctly configuring this sequence ensures authentication, routing, and error handling behave as intended across your web API.

What is the difference between convention-based and factory-based middleware in ASP.NET Core?

Convention-based middleware relies on standard class structures and dependency injection, while factory-based middleware uses the IMiddleware interface for more explicit lifetime management. Choosing between them depends on your application's scoped service requirements and pipeline complexity.

How do I implement conditional pipeline branching with MapWhen in ASP.NET Core?

Conditional pipeline branching uses MapWhen and UseWhen to evaluate request conditions and route processing dynamically. Implementing these patterns allows you to execute specialized middleware branches only for specific API endpoints or request criteria.

What is the best way to handle exceptions in an ASP.NET Core request pipeline?

Handling exceptions in the ASP.NET Core request pipeline is best achieved using built-in and custom exception handling strategies, including the IExceptionHandler interface. This approach ensures robust error capture and consistent API responses across all endpoints.

Can I write inline middleware for simple request logging in ASP.NET Core?

You can write inline middleware directly within the Configure method for simple request logging tasks in ASP.NET Core. This approach is ideal for lightweight, single-use pipeline tasks without the overhead of creating a dedicated convention-based class.