IDE-Tools · Foto: Homedust, CC BY 2.0
Aspnet Abp
Zuletzt aktualisiert:
Typ
Regel
Lizenz
CC0 1.0
Anwendungsfeld
Cursor Rules
Voraussetzungen
- Bestehendes Projekt auf Basis des ABP Frameworks
- Cursor als Editor
- Grundkenntnisse der ABP-Konventionen (DDD, Module, Auto-API)
Einordnung
Die Regel einzurichten ist einfach, entfaltet ihren Nutzen aber nur mit einem bestehenden ABP-Projekt und Grundkenntnissen davon.
Cursor-Regel, die ASP.NET-Code nach ABP-Konventionen (DDD, Module, Auto-API) generiert.
Original-Beschreibung der Autoren: Cursor rules for Aspnet Abp.
Die Regel
---
description: "Cursor rules for Aspnet Abp."
globs: **/*
alwaysApply: false
---
# ABP .NET Development Rules
You are a senior .NET backend developer and an expert in C#, ASP.NET Core, ABP Framework, and Entity Framework Core.
## Code Style and Structure
- Write concise, idiomatic C# code with accurate examples.
- Follow ABP Framework’s recommended folder and module structure (e.g., *.Application, *.Domain, *.EntityFrameworkCore, *.HttpApi).
- Use object-oriented and functional programming patterns as appropriate.
- Prefer LINQ and lambda expressions for collection operations.
- Use descriptive variable and method names (e.g., `IsUserSignedIn`, `CalculateTotal`).
- Adhere to ABP’s modular development approach to separate concerns between layers (Application, Domain, Infrastructure, etc.).
## Naming Conventions
- Use PascalCase for class names, method names, and public members.
- Use camelCase for local variables and private fields.
- Use UPPERCASE for constants.
- Prefix interface names with "I" (e.g., `IUserService`).
## C# and .NET Usage
- Use C# 10+ features when appropriate (e.g., record types, pattern matching, null-coalescing assignment).
- Leverage built-in ASP.NET Core features and middleware, as well as ABP’s modules and features (e.g., Permission Management, Setting Management).
- Use Entity Framework Core effectively for database operations, integrating with ABP’s `DbContext` and repository abstractions.
## Syntax and Formatting
- Follow the C# Coding Conventions (https://docs.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions).
- Use C#’s expressive syntax (e.g., null-conditional operators, string interpolation).
- Use `var` for implicit typing when the type is obvious.
- Keep code clean and consistent, utilizing ABP’s built-in formatting guidelines when applicable.
## Error Handling and Validation
- Use exceptions for exceptional cases, not for control flow.
- Implement proper error logging using ABP’s logging system or a third-party logger.
- Use Data Annotations or Fluent Validation for model validation within the ABP application layer.
- Leverage ABP’s global exception handling middleware for unified error responses.
- Return appropriate HTTP status codes and consistent error responses in your `HttpApi` controllers.
## API Design
- Follow RESTful API design principles in your `HttpApi` layer.
- Use ABP’s conventional HTTP API controllers and attribute-based routing.
- Integrate versioning strategies in your APIs if multiple versions are expected.
- Utilize ABP’s action filters or middleware for cross-cutting concerns (e.g., auditing).
## Performance Optimization
- Use asynchronous programming with `async/await` for I/O-bound operations.
- Always use `IDistributedCache` for caching strategies (instead of `IMemoryCache`), in line with ABP’s caching abstractions.
- Use efficient LINQ queries and avoid N+1 query problems by including related entities when needed.
- Implement pagination or `PagedResultDto` for large data sets in your application service methods.
## Key Conventions
- Use ABP’s Dependency Injection (DI) system for loose coupling and testability.
- Implement or leverage ABP’s repository pattern or use Entity Framework Core directly, depending on complexity.
- Use AutoMapper (or ABP’s built-in object mapping) for object-to-object mapping if needed.
- Implement background tasks using ABP’s background job system or `IHostedService`/`BackgroundService` where appropriate.
- Follow ABP’s recommended approach for domain events and entities (e.g., using `AuditedAggregateRoot`, `FullAuditedEntity`).
- Keep business rules in the **Domain layer**. Prefer placing them within the entity itself; if not possible, use a `DomainService`.
- Before adding a new package to the application, check if an existing package can fulfill the requirement to avoid unnecessary dependencies.
- Do not alter the dependencies between application layers (Application, Domain, Infrastructure, etc.).
**Domain Best Practices**
- [Domain Services Best Practices](https://abp.io/docs/latest/framework/architecture/best-practices/domain-services)
- [Repositories Best Practices](https://abp.io/docs/latest/framework/architecture/best-practices/repositories)
- [Entities Best Practices](https://abp.io/docs/latest/framework/architecture/best-practices/entities)
**Application Layer Best Practices**
- [Application Services Best Practices](https://abp.io/docs/latest/framework/architecture/best-practices/application-services)
- [Data Transfer Objects Best Practices](https://abp.io/docs/latest/framework/architecture/best-practices/data-transfer-objects)
**Data Access Best Practices**
- [Entity Framework Core Integration](https://abp.io/docs/latest/framework/architecture/best-practices/entity-framework-core-integration)
- [MongoDB Integration](https://abp.io/docs/latest/framework/architecture/best-practices/mongodb-integration)
Additionally, refer to the [EventHub repository](https://github.com/abpframework/eventhub) for various examples and best practices beyond testing.
## Testing
- Use the ABP startup templates that include Shouldly, NSubstitute, and xUnit for testing.
- Write unit tests using xUnit (or another supported framework), integrating with ABP’s built-in test module if available.
- Use NSubstitute (or a similar library) for mocking dependencies.
- Implement integration tests for your modules (e.g., `Application.Tests`, `Domain.Tests`), leveraging ABP’s test base classes.
## Security
- Use built-in openiddict for authentication and authorization.
- Implement proper permission checks using ABP’s permission management infrastructure.
- Use HTTPS and enforce SSL.
- Configure CORS policies according to your application's deployment needs.
## API Documentation
- Use Swagger/OpenAPI for API documentation, leveraging ABP’s built-in support (Swashbuckle.AspNetCore or NSwag).
- Provide XML comments for controllers and DTOs to enhance Swagger documentation.
… (hier gekürzt — Kopieren/Download liefert die vollständige Regel)
Im Detail
Diese Regel bringt Cursor bei, Code nach den Konventionen des ABP Frameworks (ASP.NET Boilerplate) zu generieren: Domain-Driven-Design-Struktur, Modul-Aufbau und automatisch generierte APIs. Statt generischem ASP.NET-Code entstehen Entities, Application Services und Repositories im ABP-typischen Schichtenmodell. Relevant für Teams, die bereits auf ABP setzen und wollen, dass KI-generierter Code sich nahtlos in bestehende Module einfügt statt Konventionen zu brechen. Für Projekte ohne ABP ist die Regel wenig hilfreich, da sie recht spezifisch auf dessen Modul- und DI-Konventionen zugeschnitten ist.
So einfach geht’s
- 01
Anrufen oder schreiben
Anruf, WhatsApp oder Formular. Die Ersteinschätzung am Telefon ist kostenlos.
- 02
Termin oder Fernhilfe
Ich komme zu Ihnen oder helfe per Fernhilfe am Bildschirm. Den Kostenrahmen erfahren Sie, bevor ich anfange.
- 03
Erledigt, bezahlt wird danach
Es läuft, und Sie wissen, wie es geht. Bei telefonisch vereinbarten Terminen zahlen Sie nach dem Termin bar, mit Karte oder auf Rechnung.
Beispiel aus der Praxis
Bittet man Cursor mit aktivierter Regel um eine neue Entity “Product” samt CRUD-Funktionen, entstehen automatisch eine Domain-Entity, ein Application Service und ein Repository im ABP-typischen Schichtenaufbau statt eines einzelnen generischen Controllers.
Praxis-Tipp
Bei einem Prompt wie “Erstelle einen CRUD-Service für Kunden” erzeugt die Regel automatisch IApplicationService-Interface, DTOs und AutoMapper-Profile im ABP-Stil.
Stolperfallen
Bleibt die Regel auch in Projekten ohne ABP aktiv, zwingt sie Cursor unpassende Modul- und DI-Konventionen auf und erzeugt Code, der nicht zum restlichen Projekt passt. Die Regel daher nur in echten ABP-Projekten einschalten.
Lizenz & Quelle
- Lizenz: CC0 1.0
- Quelle: PatrickJS/awesome-cursorrules (GitHub)
Häufige Fragen.
Hilft die Regel auch in einem normalen ASP.NET-Projekt ohne ABP?
Nein, sie ist speziell auf die Modul-, DDD- und DI-Konventionen von ABP zugeschnitten und bringt in Projekten ohne ABP keinen Mehrwert.
Muss ich ABP-Grundlagen kennen, um die Regel sinnvoll zu nutzen?
Ja, ohne Verständnis von ABPs Schichtenmodell lässt sich schwer beurteilen, ob der generierte Code tatsächlich den Konventionen entspricht.
Ersetzt die Regel eigene Code-Reviews?
Nein, sie steuert nur die Code-Generierung von Cursor in Richtung ABP-Konventionen, eine Prüfung des Ergebnisses bleibt weiterhin nötig.
Inhalt ansehen (aspnet-abp.mdc)
Lade …
Erfahrungen & Kommentare.
Funktioniert der Regel bei Ihnen? Tipps, Stolperfallen, Varianten — teilen Sie es mit der Community.
Lade Kommentare …
Passt dazu.
AI Agent Specialist
Cursor-Regel für diszipliniertes, klar abgegrenztes Agenten-Verhalten statt unstrukturierter KI-Antworten.
Alpha Skills Quant Factor Research
Cursor-Regel für methodisch saubere quantitative Faktor-Recherche im Trading-Umfeld.
Android Jetpack Compose
Cursor-Regel für idiomatischen, deklarativen Android-UI-Code mit Jetpack Compose.
