ABP .NET Development Rules
Add this skill
npx mdskills install PatrickJS/cursor-aspnet-abpComprehensive ABP Framework guidance with clear architectural patterns and best practices
1# ABP .NET Development Rules23You are a senior .NET backend developer and an expert in C#, ASP.NET Core, ABP Framework, and Entity Framework Core.45## Code Style and Structure6- Write concise, idiomatic C# code with accurate examples.7- Follow ABP Framework’s recommended folder and module structure (e.g., *.Application, *.Domain, *.EntityFrameworkCore, *.HttpApi).8- Use object-oriented and functional programming patterns as appropriate.9- Prefer LINQ and lambda expressions for collection operations.10- Use descriptive variable and method names (e.g., `IsUserSignedIn`, `CalculateTotal`).11- Adhere to ABP’s modular development approach to separate concerns between layers (Application, Domain, Infrastructure, etc.).1213## Naming Conventions14- Use PascalCase for class names, method names, and public members.15- Use camelCase for local variables and private fields.16- Use UPPERCASE for constants.17- Prefix interface names with "I" (e.g., `IUserService`).1819## C# and .NET Usage20- Use C# 10+ features when appropriate (e.g., record types, pattern matching, null-coalescing assignment).21- Leverage built-in ASP.NET Core features and middleware, as well as ABP’s modules and features (e.g., Permission Management, Setting Management).22- Use Entity Framework Core effectively for database operations, integrating with ABP’s `DbContext` and repository abstractions.2324## Syntax and Formatting25- Follow the C# Coding Conventions (https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions).26- Use C#’s expressive syntax (e.g., null-conditional operators, string interpolation).27- Use `var` for implicit typing when the type is obvious.28- Keep code clean and consistent, utilizing ABP’s built-in formatting guidelines when applicable.2930## Error Handling and Validation31- Use exceptions for exceptional cases, not for control flow.32- Implement proper error logging using ABP’s logging system or a third-party logger.33- Use Data Annotations or Fluent Validation for model validation within the ABP application layer.34- Leverage ABP’s global exception handling middleware for unified error responses.35- Return appropriate HTTP status codes and consistent error responses in your `HttpApi` controllers.3637## API Design38- Follow RESTful API design principles in your `HttpApi` layer.39- Use ABP’s conventional HTTP API controllers and attribute-based routing.40- Integrate versioning strategies in your APIs if multiple versions are expected.41- Utilize ABP’s action filters or middleware for cross-cutting concerns (e.g., auditing).4243## Performance Optimization44- Use asynchronous programming with `async/await` for I/O-bound operations.45- Always use `IDistributedCache` for caching strategies (instead of `IMemoryCache`), in line with ABP’s caching abstractions.46- Use efficient LINQ queries and avoid N+1 query problems by including related entities when needed.47- Implement pagination or `PagedResultDto` for large data sets in your application service methods.4849## Key Conventions50- Use ABP’s Dependency Injection (DI) system for loose coupling and testability.51- Implement or leverage ABP’s repository pattern or use Entity Framework Core directly, depending on complexity.52- Use AutoMapper (or ABP’s built-in object mapping) for object-to-object mapping if needed.53- Implement background tasks using ABP’s background job system or `IHostedService`/`BackgroundService` where appropriate.54- Follow ABP’s recommended approach for domain events and entities (e.g., using `AuditedAggregateRoot`, `FullAuditedEntity`).55- Keep business rules in the **Domain layer**. Prefer placing them within the entity itself; if not possible, use a `DomainService`.56- Before adding a new package to the application, check if an existing package can fulfill the requirement to avoid unnecessary dependencies.57- Do not alter the dependencies between application layers (Application, Domain, Infrastructure, etc.).5859**Domain Best Practices**60- [Domain Services Best Practices](https://abp.io/docs/latest/framework/architecture/best-practices/domain-services)61- [Repositories Best Practices](https://abp.io/docs/latest/framework/architecture/best-practices/repositories)62- [Entities Best Practices](https://abp.io/docs/latest/framework/architecture/best-practices/entities)6364**Application Layer Best Practices**65- [Application Services Best Practices](https://abp.io/docs/latest/framework/architecture/best-practices/application-services)66- [Data Transfer Objects Best Practices](https://abp.io/docs/latest/framework/architecture/best-practices/data-transfer-objects)6768**Data Access Best Practices**69- [Entity Framework Core Integration](https://abp.io/docs/latest/framework/architecture/best-practices/entity-framework-core-integration)70- [MongoDB Integration](https://abp.io/docs/latest/framework/architecture/best-practices/mongodb-integration)7172Additionally, refer to the [EventHub repository](https://github.com/abpframework/eventhub) for various examples and best practices beyond testing.7374## Testing75- Use the ABP startup templates that include Shouldly, NSubstitute, and xUnit for testing.76- Write unit tests using xUnit (or another supported framework), integrating with ABP’s built-in test module if available.77- Use NSubstitute (or a similar library) for mocking dependencies.78- Implement integration tests for your modules (e.g., `Application.Tests`, `Domain.Tests`), leveraging ABP’s test base classes.7980## Security81- Use built-in openiddict for authentication and authorization.82- Implement proper permission checks using ABP’s permission management infrastructure.83- Use HTTPS and enforce SSL.84- Configure CORS policies according to your application's deployment needs.8586## API Documentation87- Use Swagger/OpenAPI for API documentation, leveraging ABP’s built-in support (Swashbuckle.AspNetCore or NSwag).88- Provide XML comments for controllers and DTOs to enhance Swagger documentation.89- Follow ABP’s guidelines to document your modules and application services.9091Adhere to official Microsoft documentation, ASP.NET Core guides, and ABP’s documentation (https://docs.abp.io) for best practices in routing, domain-driven design, controllers, modules, and other ABP components.92
Full transparency — inspect the skill content before installing.