controllers

Creates ASP.NET Core REST controllers using MediatR dispatch and ProblemDetails error responses.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Many .NET Web APIs end up with business logic in controllers, inconsistent error responses, and no centralized dispatch mechanism. This Skill provides patterns to keep controllers thin, route work through MediatR, and return standardized ProblemDetails responses for errors.

Core Features & Use Cases

  • Base Controller Pattern: Centralizes access to ISender so controllers delegate to MediatR handlers rather than containing business logic.
  • CRUD Controller Template: Demonstrates common GET/POST/PUT/DELETE endpoints with appropriate status codes and validation error responses.
  • Global Exception Handler: Maps domain and validation exceptions to ProblemDetails with appropriate HTTP status codes and centralized logging.
  • Use Case: Implementing an OrdersController that handles pagination, retrieval, creation, updates, and deletions while delegating to MediatR handlers and returning consistent error payloads.

Quick Start

Create an OrdersController that inherits from BaseController, forwards commands and queries to MediatR, and returns ProblemDetails for errors.

Frequently Asked Questions about controllers

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

FAQPage Schema
How do I keep ASP.NET Core API controllers thin using MediatR dispatch?

To keep ASP.NET Core API controllers thin, use a BaseController that resolves ISender to dispatch commands and queries to MediatR handlers, ensuring controllers contain no business logic and only handle HTTP routing.

How do I return standardized ProblemDetails for validation errors in ASP.NET Core?

Standardized ProblemDetails for validation errors are generated by combining FluentValidation for input validation with a global exception handler registered in Program.cs, which maps domain and validation exceptions to consistent error payloads.

Do I need a global exception handler to return ProblemDetails from MediatR controllers?

Yes, a global exception handler registered in Program.cs is required to intercept MediatR handler exceptions and map them to ProblemDetails responses with appropriate HTTP status codes and centralized logging.

What is the best way to structure CRUD endpoints in an ASP.NET Core Web API?

The best way to structure CRUD endpoints is inheriting from a BaseController that forwards GET, POST, PUT, and DELETE requests to MediatR handlers, returning appropriate HTTP status codes and ProblemDetails for errors.

Can I use this MediatR controller pattern without FluentValidation?

FluentValidation is a required dependency for this MediatR controller pattern to ensure proper input validation and generate the validation error ProblemDetails responses expected by the global exception handler.