Cursor 與 .NET:截至 11 月 01 日的一週 7 條規則
This week in Cursor + .NET — 7 rules (week ending November 01, 2026)
這週的 Cursor 與 .NET 專題整理了 7 條供資深 C#/.NET 工程師使用的每日規則,涵蓋背景工作、Channels、JSON 序列化、架構測試、整合測試及非同步程式碼。文章亦提供免費 Cursor 規則 arch-core-lite.mdc,並列出一次性付費 £9.00 的完整套件。
Every weekday a single, opinionated rule for senior C#/.NET engineers using Cursor. Here's the full week in one read — canonical posts live on the Agentic Architect blog.
7 daily senior rules
Rule 22: BackgroundService Over Task.Run
Sun 01 Nov
Long-running work in ASP.NET Core goes in a BackgroundService, not Task.Run inside a controller. Cursor will happily fire Task.Run and call it "async work" — your request thread will die mid-execution and you'll never know why. Catch Task.Run outside test code and propose a hosted service.
Rule 21: Channels for Producer Consumer
Sat 31 Oct
System.Threading.Channels beats BlockingCollection and beats roll-your-own queue plus SemaphoreSlim. The AI reaches for ConcurrentQueue every time and stitches it together by hand. A rule that detects producer/consumer patterns and proposes Channel will save you a class.
Rule 20: Source-Generated JSON Serialisation
Fri 30 Oct
Reflection-based System.Text.Json is fine for prototypes. For hot paths and AOT, use JsonSerializable source generation. Cursor never thinks of this on its own — add a rule that flags new DTO classes and asks whether they should be source-generated.
Rule 19: NetArchTest for Boundaries
Thu 29 Oct
Architectural rules belong in tests, not in code review. Encode them as NetArchTest assertions ("no class in Domain references EntityFrameworkCore") and they fail your build instead of your standup. Add the corresponding test whenever a new layer or project is introduced.
Rule 18: WebApplicationFactory for Integration Tests
Wed 28 Oct
In-memory EF Core providers lie. Use WebApplicationFactory with Testcontainers (SQL Server, Postgres) for real integration coverage. Cursor defaults to UseInMemoryDatabase — it passes locally and ships the bug to production. Flag the in-memory provider in test projects.
Rule 17: ConfigureAwait false in Libraries
Tue 27 Oct
Library code (non-ASP.NET) should ConfigureAwait false on every awaited Task. ASP.NET Core code should not. Cursor mixes the two contexts in the same solution. Detect the project type and enforce the right default.
Rule 16: async void Outside Event Handlers
Mon 26 Oct
async void is a deadlock and unhandled-exception trap everywhere except UI event handlers. The AI uses it routinely for "fire and forget" — wrong answer every time. Flag it on sight.
Try one rule before you trust the whole kit
The free arch-core-lite.mdc is one drop-in Cursor rule that ends the morning re-explanation ritual. Install in 60 seconds, see whether Cursor actually remembers your DI lifetimes, and decide for yourself whether the full kit is worth £9.00.
-
Free sample:
arch-core-lite.mdcon GitHub - Full kit (£9.00, one-time): Agentic Architect Kit
- Daily rules feed: https://agentic-architect.dev/blog/
Canonical home for everything in this digest: https://agentic-architect.dev/blog/.
來源:DEV Community · dev.to