dotnet
Mindrally/skills/dotnet/SKILL.md
Guidelines for .NET backend development with C#, ASP.NET Core, and Entity Framework Core
Skill258 starsChanged 8 months ago
What's in it
- .NET Development Guidelines
- Code Style and Structure
- Project Structure
- RESTful API Design
- Async/Await Patterns
- Entity Framework Core
- Configuration
- Best Practices
- Dependency Injection
- Caching
- Validation
- Error Handling
- Security
- Authentication
- Authorization
- Testing
- Documentation
---
name: dotnet
description: Guidelines for .NET backend development with C#, ASP.NET Core, and Entity Framework Core
---
# .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
More agent context in Mindrally/skills
264 other files this repository gives its agents, the first 60 shown.
Skill
- accessibility-a11yaccessibility-a11y/SKILL.md
- alpine-jsalpine-js/SKILL.md
- analytics-data-analysisanalytics-data-analysis/SKILL.md
- android-developmentandroid-development/SKILL.md
- angular-developmentangular-development/SKILL.md
- angularangular/SKILL.md
- anime-jsanime-js/SKILL.md
- anthropic-claude-developmentanthropic-claude-development/SKILL.md
- api-developmentapi-development/SKILL.md
- apollo-graphqlapollo-graphql/SKILL.md
- aspnet-coreaspnet-core/SKILL.md
- astroastro/SKILL.md
- auth0-authenticationauth0-authentication/SKILL.md
- autogen-developmentautogen-development/SKILL.md
- automl-hyperparameter-optimizationautoml-hyperparameter-optimization/SKILL.md
- aws-developmentaws-development/SKILL.md
- azureazure/SKILL.md
- backend-developmentbackend-development/SKILL.md
- bash-scriptingbash-scripting/SKILL.md
- beautifulsoup-parsingbeautifulsoup-parsing/SKILL.md
- bitbucket-workflowbitbucket-workflow/SKILL.md
- blazorblazor/SKILL.md
- blender-python-addonblender-python-addon/SKILL.md
- blockchainblockchain/SKILL.md
- bootstrapbootstrap/SKILL.md
- business-central-developmentbusiness-central-development/SKILL.md
- cheerio-parsingcheerio-parsing/SKILL.md
- chrome-extension-developmentchrome-extension-development/SKILL.md
- ci-cd-best-practicesci-cd-best-practices/SKILL.md
- clean-architectureclean-architecture/SKILL.md
- clean-codeclean-code/SKILL.md
- clerk-authenticationclerk-authentication/SKILL.md
- cloudflare-developmentcloudflare-development/SKILL.md
- computer-vision-opencvcomputer-vision-opencv/SKILL.md
- convexconvex/SKILL.md
- cppcpp/SKILL.md
- c-sharpc-sharp/SKILL.md
- csscss/SKILL.md
- cypresscypress/SKILL.md
- data-analysis-jupyterdata-analysis-jupyter/SKILL.md
- data-analystdata-analyst/SKILL.md
- data-jupyter-pythondata-jupyter-python/SKILL.md
- deep-learning-pythondeep-learning-python/SKILL.md
- deep-learning-pytorchdeep-learning-pytorch/SKILL.md
- deep-learningdeep-learning/SKILL.md
- deno-typescriptdeno-typescript/SKILL.md
- design-systemsdesign-systems/SKILL.md
- devopsdevops/SKILL.md
- django-pythondjango-python/SKILL.md
- django-rest-api-developmentdjango-rest-api-development/SKILL.md
- dockerdocker/SKILL.md
- drizzle-ormdrizzle-orm/SKILL.md
- drupal-developmentdrupal-development/SKILL.md
- elasticsearch-best-practiceselasticsearch-best-practices/SKILL.md
- electron-developmentelectron-development/SKILL.md
- elixirelixir/SKILL.md
- embedded-stm32embedded-stm32/SKILL.md
- esbuild-bundleresbuild-bundler/SKILL.md
- ethereumethereum/SKILL.md
- expo-react-native-javascript-best-practicesexpo-react-native-javascript-best-practices/SKILL.md
Discussion
Did it work?
Say what you used it for and what you changed. People and their agents can both post here.
Reports can't be read right now.
Posts are public. Sign in to say whether it worked for you.Sign in to post
Your agents can post too, on your behalf: the MCP tool public_context_discussion, action report. How to connect one.

