Add C#/.NET architectural guardrails rule#291
Add C#/.NET architectural guardrails rule#291agenticstandardcontact-byte wants to merge 3 commits into
Conversation
📝 WalkthroughWalkthroughThis PR introduces a new Cursor rule file that defines architectural guardrails and best practices for C# and .NET projects. The rule enforces layer separation, rejects common anti-patterns, requires explicit clarification when context is uncertain, and documents preferred .NET idioms and change practices. ChangesC# and .NET Architectural Rule
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@rules/csharp-dotnet-architecture.mdc`:
- Line 25: Update the rule that currently forbids "DateTime.Now" so it also
explicitly forbids "DateTime.UtcNow" (i.e., change the prohibition from
DateTime.Now to include DateTime.UtcNow) to match the anti-pattern section; edit
the line that lists forbidden APIs in the Domain rule (the entry containing
DateTime.Now) to add DateTime.UtcNow so both UTC and local DateTime access are
consistently disallowed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7b05aa41-9f85-4e7d-b41a-16a49ce993cc
📒 Files selected for processing (2)
README.mdrules/csharp-dotnet-architecture.mdc
|
|
||
| Treat the codebase as a layered system (whatever flavour: Onion, Clean, Hexagonal, classic n-tier). **Detect the layer of the file under edit** from its path (`/Domain`, `/Application`, `/Infrastructure`, `/Api`, `/Web`, `/Persistence`, etc.). Then enforce: | ||
|
|
||
| - **Domain** never references `Microsoft.EntityFrameworkCore`, `HttpClient`, `IConfiguration`, `ILogger<T>`, `DateTime.Now`, `Environment.*`, or any concrete I/O. |
There was a problem hiding this comment.
Align DateTime prohibition with the anti-pattern section.
Line 25 forbids DateTime.Now but omits DateTime.UtcNow, while Line 40 bans both. Add DateTime.UtcNow here too so boundary checks stay consistent and don’t leave a loophole.
Suggested wording tweak
-- **Domain** never references `Microsoft.EntityFrameworkCore`, `HttpClient`, `IConfiguration`, `ILogger<T>`, `DateTime.Now`, `Environment.*`, or any concrete I/O.
+- **Domain** never references `Microsoft.EntityFrameworkCore`, `HttpClient`, `IConfiguration`, `ILogger<T>`, `DateTime.Now`, `DateTime.UtcNow`, `Environment.*`, or any concrete I/O.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@rules/csharp-dotnet-architecture.mdc` at line 25, Update the rule that
currently forbids "DateTime.Now" so it also explicitly forbids "DateTime.UtcNow"
(i.e., change the prohibition from DateTime.Now to include DateTime.UtcNow) to
match the anti-pattern section; edit the line that lists forbidden APIs in the
Domain rule (the entry containing DateTime.Now) to add DateTime.UtcNow so both
UTC and local DateTime access are consistently disallowed.
Co-authored-by: Cursor <cursoragent@cursor.com>
What this adds
rules/csharp-dotnet-architecture.mdcWhy
The current README has no dedicated C#/.NET entry under Backend and Full-Stack (Java/Spring, Rails, Laravel, FastAPI, NestJS are all represented, but not .NET). This contribution fills that gap with a scoped rule focused on the architectural concerns senior .NET developers actually want enforced by an AI pair.
What the rule does
Activates on
**/*.cs,**/*.csproj,**/*.sln. Five operating principles:Microsoft.EntityFrameworkCorereferences in Domain, blocks rawIConfigurationreads in Application).HttpClientinstantiated withnew, capturedDateTime.Nowin domain code,async voidoutside event handlers,Task.Result/.Wait()in async paths,throw ex;.recordvsclass, constructor injection,IOptions<T>,CancellationTokenflow.Frontmatter
Follows the format from CONTRIBUTING.md:
Attribution / licensing
Adapted from the open-source
arch-core-lite.mdcwhich is MIT-licensed. The original is mine; the file in this PR has been edited for tone and to remove product chrome per the CONTRIBUTING guideline ("keep descriptions neutral, practical, and focused on reusable Cursor rule value").Checklist
rules/with required frontmatter**/*)Summary by CodeRabbit