Skip to main content
skill CX Codex

dotnet — Claude Code skill: .NET backend guidelines

Gives your agent rules for C#, ASP.NET Core and Entity Framework Core: project layout, async/await, DI, caching, tests.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add Mindrally/skills --skill dotnet -a claude-code
Open on GitHub

What dotnet does

The skill spells out how to build a .NET backend: idiomatic C#, Clean Architecture, REST endpoints with the right HTTP methods and status codes. Your agent gets a fixed layout — src/Domain, src/Application, src/Infrastructure, src/WebApi, plus tests/UnitTests and tests/IntegrationTests — and puts code where it belongs instead of improvising.

Inside are per-layer rules. Async/await: Async suffixes, CancellationToken, no .Result or .Wait(). EF Core: Fluent API, migrations, AsNoTracking() on reads, Include/ThenInclude, projections instead of pulling whole entities. Add DI with constructor injection registered in Program.cs, caching via IMemoryCache and IDistributedCache, validation with FluentValidation and Data Annotations, JWT with refresh token rotation, policy-based authorization, xUnit with Moq and WebApplicationFactory, Swagger/OpenAPI.

This is a text skill — instructions for the agent, not a code generator. If your project already runs a different style, say controllers without Clean Architecture or Dapper instead of EF Core, the rules will fight the existing codebase. That is a reason to fork the skill or skip it.

What it helps with

  • split a solution into Domain, Application, Infrastructure and WebApi
  • convert blocking EF Core calls to async with CancellationToken
  • kill N+1 queries with Include and projections
  • wire up JWT auth with refresh token rotation
  • add integration tests on WebApplicationFactory

Example prompts for the agent

  • Create a UsersController following the dotnet skill: pagination, filters, version in the path
  • Rewrite this repository with AsNoTracking and projections, check for N+1
  • Set up service registration and the Options pattern in Program.cs

How to install dotnet

1Skills CLI (Vercel)

npx skills add Mindrally/skills --skill dotnet -a claude-code

2Manually: put the files in place

~/.claude/skills/dotnet/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/dotnet/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about dotnet

How do I install the dotnet skill in Claude?

Run npx skills add Mindrally/skills --skill dotnet -a claude-code. The file lands at ~/.claude/skills/dotnet/SKILL.md.

What does the dotnet skill do?

It hands your agent .NET backend rules: C# style, solution structure, async/await, EF Core, DI, caching, validation, security and testing. The agent follows them while writing or editing code.

Does the skill force Clean Architecture?

Yes, the project structure is defined as Domain, Application, Infrastructure and WebApi. If your layout differs, you will need to edit the rules to match.

Source text

SKILL.md · Apache-2.0
---
name: dotnet
description: Guidelines for .NET backend development with C#, ASP.NET Core, and Entity Framework Core
metadata:
  maintainer: Mindrally
  source: https://github.com/Mindrally/skills
---

# .NET Development Guidelines

You are an expert in .NET backend development with deep knowledge of C#, ASP.NET Core, Entity Framework Core, and modern .NET practices.

## Code Style and Structure

- Write concise, idiomatic C# code with accurate examples
- Follow .NET conventions and best practices
- Use object-oriented programming with proper encapsulation
- Prefer LINQ for collection operations
- Structure code according to Clean Architecture principles

## Project Structure

```
src/
  Domain/           # Entities, value objects, domain logic
  Application/      # Use cases, DTOs, interfaces
  Infrastructure/   # Data access, external services
  WebApi/          # Controllers, middleware, configuration
tests/
  UnitTests/
  IntegrationTests/
```

## RESTful API Design

- Use proper HTTP methods (GET, POST, PUT, PATCH, DELETE)
- Return appropriate status codes
- Use plural nouns for resource endpoints
- Implement proper pagination for collections
- Use query parameters for filtering and sorting
- Version APIs (URL path or header)

```csharp
[ApiController]
[Route("api/v1/[controller]")]
public class UsersController : ControllerBase
{
    [HttpGet]
    public async Task<ActionResult<IEnumerable<UserDto>>> GetUsers([FromQuery] PaginationParams pagination)

    [HttpGet("{id}")]
    public async Task<ActionResult<UserDto>> GetUser(int id)

    [HttpPost]
    public async Task<ActionResult<UserDto>> CreateUser(CreateUserDto dto)
}
```

## Async/Await Patterns

- Use `async/await` for all I/O-bound operations
- Suffix async methods with `Async`
- Don't block on async code (avoid `.Result` and `.Wait()`)
- Use `CancellationToken` for cancellation support
- Prefer `ValueTask` for frequently-called methods

## Entity Framework Core

### Configuration
- Use Fluent API for entity configuration
- Configure relationships explicitly
- Use migrations for schema changes
- Enable nullable reference types

### Best Practices
- Use `AsNoTracking()` for read-only queries
- Implement the Repository pattern for data access
- Use Include/ThenInclude for eager loading
- Avoid N+1 query problems
- Use projections for optimized queries

```csharp
public async Task<IEnumerable<UserDto>> GetUsersAsync()
{
    return await _context.Users
        .AsNoTracking()
        .Select(u => new UserDto
        {
            Id = u.Id,
            Name = u.Name
        })
        .ToListAsync();
}
```

## Dependency Injection

- Use constructor injection
- Register services in `Program.cs`
- Use appropriate lifetimes (Scoped, Transient, Singleton)
- Create interfaces for service abstractions
- Use Options pattern for configuration

```csharp
builder.Services.AddScoped<IUserService, UserService>();
builder.Services.Configure<JwtSettings>(builder.Configuration.GetSection("Jwt"));
```

## Caching

- Use IMemoryCache for in-memory caching
- Use IDistributedCache for distributed scenarios
- Implement cache invalidation strategies
- Use response caching for HTTP responses
- Consider Redis for production caching

## Validation

- Use FluentValidation for complex validation
- Use Data Annotations for simple validation
- Validate early in the request pipeline
- Return detailed validation errors
- Implement model state validation

## Error Handling

- Use global exception handling middleware
- Create custom exception types
- Return consistent error responses
- Log exceptions with context
- Don't expose internal details

## Security

### Authentication
- Use JWT tokens for API authentication
- Implement refresh token rotation
- Store tokens securely
- Use ASP.NET Core Identity when appropriate

### Authorization
- Use policy-based authorization
- Implement resource-based authorization
- Apply `[Authorize]` attributes appropriately
- Use claims for fine-grained permissions

## Testing

- Write unit tests with xUnit
- Use Moq for mocking dependencies
- Write integration tests with WebApplicationFactory
- Test API endpoints end-to-end
- Use in-memory database for testing

## Documentation

- Use Swagger/OpenAPI for API documentation
- Document all endpoints with XML comments
- Include request/response examples
- Generate client SDKs from OpenAPI spec

© Mindrally · Apache-2.0 · Mindrally/skills

Similar skills

Everything for Backend and APIs →

From the same set168

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor