Back to Rules
C#

.NET Coding Rules: Best Practices for C#, ASP.NET Core & Entity Framework

Claude Directory November 29, 2025
0 copies 1 downloads

Elevate your .NET backend development with rewritten expert guidelines on C# code style, API design, security, performance, and testing for ASP.NET Core and Entity Framework Core.

Rule Content
Follow these actionable .NET development checklists to build robust, scalable backend applications using C#, ASP.NET Core, and Entity Framework Core:

### Code Organization & Style
- Craft clean, idiomatic C# code with precise, real-world examples.
- Adhere to standard .NET and ASP.NET Core patterns, blending OOP and functional approaches where suitable.
- Opt for LINQ queries and lambdas to handle collections efficiently.
- Choose clear, meaningful names like `ValidateUserCredentials` or `ComputeOrderSum`.
- Organize projects into standard folders: Controllers, Models, Services, and more.

### Naming Standards
- Apply PascalCase to classes, methods, and public properties.
- Use camelCase for private fields and local variables.
- Define constants in UPPERCASE.
- Start interfaces with 'I', such as `IOrderRepository`.

### Modern C# & Framework Features
- Harness C# 10+ capabilities like records, pattern matching, and null assignment operators.
- Utilize ASP.NET Core middleware and built-in tools for streamlined development.
- Employ Entity Framework Core for optimal data access and ORM operations.

### Formatting & Syntax
- Align with official C# style guidelines for consistency.
- Leverage expressive features: null-conditional operators (`?.`), string interpolation (`$""`), and `var` for obvious types only.

### Error Management & Validation
- Reserve exceptions for true errors, avoiding them for regular logic.
- Integrate logging via .NET's ILogger or external libraries.
- Apply Data Annotations or FluentValidation for input checks.
- Set up middleware for centralized exception handling.
- Deliver standard HTTP codes with uniform error formats.

### REST API Principles
- Design APIs following REST standards.
- Enable attribute-based routing in controllers.
- Add API versioning for backward compatibility.
- Use filters for shared logic like logging or auth.

### Performance Tips
- Always use `async/await` for I/O tasks.
- Apply caching with IMemoryCache or distributed options.
- Optimize LINQ to prevent N+1 issues and use efficient queries.
- Add pagination to manage large result sets.

### Core Patterns
- Rely on Dependency Injection for modular, testable code.
- Choose repositories or direct EF Core based on project scale.
- Use AutoMapper for DTO conversions when necessary.
- Schedule background jobs via BackgroundService.

### Testing Strategies
- Create unit tests with xUnit, NUnit, or MSTest.
- Mock dependencies using Moq or NSubstitute.
- Build integration tests covering API routes.

### Security Essentials
- Enable Authentication/Authorization middleware.
- Implement JWT for API token-based auth.
- Mandate HTTPS and configure CORS securely.

### Documentation
- Generate Swagger docs via Swashbuckle.AspNetCore.
- Add XML comments to controllers and models for richer API specs.

Comments

More Rules

View all
AI/ML

GLM-4.7 Optimized Config & System Prompt Designer

Expert system prompt for designing high-performance configurations tailored to GLM-4.7's strengths in coding, reasoning, tool use, and multilingual tasks, backed by benchmarks like SWE-bench and τ²-Bench.

C
Community
AI/ML

GLM-4.7 Open-Source Coding Expert: Optimized System Prompt

Leverage GLM-4.7's top benchmarks in SWE-bench, LiveCodeBench, and more with this system prompt designed for generating clean, secure, open-source-ready code, stunning UIs, and agentic workflows.

C
Community
AI/ML

GLM-4.7 Optimized Coding Agent

This system prompt transforms an AI into GLM-4.7, a benchmark-leading coding agent excelling in agentic workflows, tool use, multilingual coding, and complex reasoning with verified best practices for production-ready open-source development.

C
Community
DevOps

Agentic Dev Loop: Autonomous Jira-Driven Coding Agent with GitHub CI Self-Healing

Ralph, a persistent autonomous AI agent, implements Jira tickets through an endless loop until 100% test success, with GitHub PRs, Jules AI reviews, and CI self-healing for reliable development workflows.

C
Claude Directory
AI/ML

Türk Hukuku Uzmanı AI Agent: Güvenilir Yasal Danışman System Prompt

Claude'u Türk hukuku alanında dünyanın en önde gelen uzmanı olarak yapılandıran, yapılandırılmış yanıtlar, zorunlu uyarılar ve etik sınırlarla donatılmış profesyonel AI agent promptu.

C
Community
Database

PostgreSQL Best Practices: Expert Subagent Guide

Expert subagent providing production-ready PostgreSQL guidance on schema design, query optimization, security, performance tuning, and administration with structured, actionable advice and official references.

C
Claude Directory