csharp-coding-standard…
Defines the C# coding standards, patterns, and conventions to be applied consistently across all C# projects. Rules cover naming, structure, async patterns,…
Defines the coding standards, patterns, and conventions for ASP.NET Core REST API controllers. Rules cover routing, HTTP verbs, response types, XML documentation, dependency injection, and asynchronous execution. Apply these rules uniformly to ensure a consistent, predictable,
$ npx -y skills add linuxchata/ai-playbook --skill csharp-api-controller-standards --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/csharp-api-controller-standardsContext preview
The summary Claude sees to decide when to auto-load this skill.
Defines the coding standards, patterns, and conventions for ASP.NET Core REST API controllers. Rules cover routing, HTTP verbs, response types, XML documentation, dependency injection, and asynchronous execution. Apply these rules uniformly to ensure a consistent, predictable,
name: csharp-api-controller-standards description: Defines the coding standards, patterns, and conventions for ASP.NET Core REST API controllers. Rules cover routing, HTTP verbs, response types, XML documentation, dependency injection, and asynchronous execution. Apply these rules uniformly to ensure a consistent, predictable, and well-documented API surface. metadata: version: 1.0.0
Defines the coding standards, patterns, and conventions for ASP.NET Core REST API controllers. Rules cover routing, HTTP verbs, response types, XML documentation, dependency injection, and asynchronous execution. Apply these rules uniformly to ensure a consistent, predictable, and well-documented API surface.
---
// ✅ Correct
[ApiController]
[Route("api/[controller]")]
public sealed class OrdersController : ControllerBase
{
}
// ❌ Wrong
public class OrdersController : Controller { }---
[HttpGet("{id:guid}")]
public async Task<IActionResult> GetByIdAsync(Guid id, CancellationToken cancellationToken)---
Use the correct HTTP verb corresponding to the operation:
| Verb | Usage | Idempotent | |---|---|---| | `[HttpGet]` | Retrieve a resource or collection | Yes | | `[HttpPost]` | Create a new resource or execute an action | No | | `[HttpPut]` | Fully update an existing resource | Yes | | `[HttpPatch]` | Partially update an existing resource | No | | `[HttpDelete]` | Remove a resource | Yes |
Explicitly state where parameters are bound from to avoid ambiguity and improve OpenAPI generation:
[HttpGet("{id:guid}/items")]
public async Task<IActionResult> GetItemsAsync(
[FromRoute] Guid id,
[FromQuery] int page,
CancellationToken cancellationToken)---
Always return the appropriate HTTP status code for the outcome:
[HttpPost]
public async Task<IActionResult> CreateAsync([FromBody] CreateOrderRequest request, CancellationToken cancellationToken)
{
var id = await _service.CreateAsync(request, cancellationToken);
return CreatedAtAction(nameof(GetByIdAsync), new { id = id }, request);
}Explicitly declare all possible status codes and their corresponding return types using `[ProducesResponseType]`. This is critical for generating accurate OpenAPI/Swagger documentation.
[HttpGet("{id:guid}")]
[ProducesResponseType(typeof(OrderDto), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetByIdAsync([FromRoute] Guid id, CancellationToken cancellationToken)---
Every controller action must be fully documented using XML comments.
XML comment tags:
/// <summary>
/// Retrieves a specific order by its unique identifier.
/// </summary>
/// <param name="id">The unique identifier of the order.</param>
/// <param name="cancellationToken">A cancellation token.</param>
/// <returns>The HTTP response.</returns>
/// <response code="200">A specific order.</response>
/// <response code="404">If the order is not found.</response>
[HttpGet("{id:guid}")]
[ProducesResponseType(typeof(OrderDto), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetByIdAsync([FromRoute] Guid id, CancellationToken cancellationToken)
{
// ... implementation
}---
Always use constructor injection for services required by the controller.
**If using C# 12 or later**, prefer **Primary Constructors** to eliminate boilerplate:
// ✅ Correct (C# 12+)
[ApiController]
[Route("api/[controllerRules, skills, and guidelines for AI coding assistants – Claude, Cursor, and beyond.
Repo: linuxchata/ai-playbook
Defines the C# coding standards, patterns, and conventions to be applied consistently across all C# projects. Rules cover naming, structure, async patterns,…
Defines the testing standards, patterns, and conventions for all C# unit and integration test projects. Rules cover test framework usage, naming, structure,…