controller-patterns

Route API requests through MediatR commands and queries with ProblemDetails error handling.

4|1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill controller-patterns-faysilalshareef
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: controller-patterns
Source: https://github.com/FaysilAlshareef/dotnet-ai-kit/tree/main/skills/api/controller-patterns
Command: npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill controller-patterns-faysilalshareef

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

The struggle of keeping controllers thin and focused while coordinating complex business workflows is solved by delegating logic to MediatR handlers, ensuring maintainable architecture.

Core Features & Use Cases

  • Thin controllers dispatch to MediatR handlers, keeping concerns separate and testable.
  • Follow RESTful routing with resource-based URLs and explicit response types via ProducesResponseType.
  • Robust model binding and error handling with ApiController, CancellationToken support, and consistent ProblemDetails.

Quick Start

Configure your ASP.NET Core app to use ApiController, register MediatR, and implement handlers to handle requests.

Frequently Asked Questions about controller-patterns

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

FAQPage Schema
How do I keep ASP.NET Core controllers thin and testable?

To keep ASP.NET Core controllers thin and testable, route API requests through MediatR commands and queries. This delegates complex business workflows to separate handlers, ensuring a maintainable architecture with separated concerns.

What is the best way to structure REST operations in ASP.NET Core Web APIs?

The best way to structure REST operations in an ASP.NET Core Web API is to use resource-based URLs with explicit response types via ProducesResponseType. This enforces standard routing and consistent error handling using ProblemDetails.

How does MediatR work with ASP.NET Core controllers for API requests?

MediatR works with ASP.NET Core controllers by dispatching API requests directly to MediatR commands and queries. Controllers simply coordinate the request, while MediatR handlers process the complex business logic asynchronously.

Can I use cancellation tokens with MediatR handlers in ASP.NET Core?

Yes, you can use cancellation tokens with MediatR handlers in ASP.NET Core. The controller pattern supports robust model binding and passes cancellation tokens to handlers to gracefully terminate long-running API operations.

How do I configure an ASP.NET Core app to use MediatR for API controllers?

To configure an ASP.NET Core app for MediatR, enable the ApiController feature, register MediatR in the dependency injection container, and implement specific request handlers to process commands and queries.

Why do my ASP.NET Core API controllers have too much business logic?

ASP.NET Core API controllers contain too much business logic when they directly coordinate complex workflows. Delegating this logic to MediatR commands and queries separates concerns, keeping controllers focused strictly on routing and HTTP response mapping.