跳到正文
DEV Community· Agentic Architect·· 2 小時前AI 評分46

本週 Cursor + .NET:截至 2026 年 10 月 25 日的一週 7 條規則

This week in Cursor + .NET — 7 rules (week ending October 25, 2026)

AI 導讀

Agentic Architect 整理了面向使用 Cursor 的資深 C#/.NET 工程師的 7 條每日規則,涵蓋值物件與實體、強型別 ID、設定綁定、例外處理、EF Core 唯讀查詢及 DI 生命週期。文中提供免費的 arch-core-lite.mdc Cursor 規則,並以 £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 15: Records for Value Objects, Classes for Entities

Sun 25 Oct

Value objects (Money, Address, Coordinates) should be records. Entities with identity (Order, Customer) should be classes with an Id. Cursor mixes these constantly. A rule that classifies based on the presence or absence of an identity property keeps the distinction honest.

→ Permalink on the blog

Rule 14: Sealed By Default

Sat 24 Oct

Mark every class sealed unless inheritance is explicitly planned. Stops Cursor inventing accidental inheritance hierarchies "for flexibility." Small but measurable virtual-call perf wins too.

→ Permalink on the blog

Rule 13: Strongly-Typed IDs

Fri 23 Oct

OrderId as record struct OrderId(Guid Value) beats raw Guid everywhere. Stops the AI passing a CustomerId where an OrderId was expected — a bug the compiler can't catch with primitive obsession but catches instantly with domain primitives.

→ Permalink on the blog

Rule 12: IOptionsSnapshot Over Raw Config

Thu 22 Oct

Business code should never call IConfiguration directly. Strongly-typed IOptions or IOptionsSnapshot bindings only. The AI loves to "just grab the config value" — refuse it and force a settings class with validation attributes.

→ Permalink on the blog

Rule 11: Rethrow, Don't throw ex

Wed 21 Oct

throw ex resets the stack trace. throw preserves it. Cursor gets this wrong about 40 percent of the time when generating catch blocks. Rewrite any naked throw ex to throw unless the exception has been explicitly wrapped.

→ Permalink on the blog

Rule 10: AsNoTracking for Reads

Tue 20 Oct

Every read-only EF Core query should call AsNoTracking. Add a rule that recognises query methods returning DTOs (not entities) and inserts the call. Cursor never does this by default and your read perf degrades silently across releases.

→ Permalink on the blog

Rule 9: Scoped Capture in Singleton

Mon 19 Oct

The single most expensive .NET runtime bug: a Singleton holding a Scoped service. Cursor cheerfully writes this without warning. Audit constructor parameters of any class registered as Singleton — if any are typically Scoped (DbContext, repositories, MediatR sender), flag it before merge.

→ Permalink on the blog


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.

Canonical home for everything in this digest: https://agentic-architect.dev/blog/.

來源:DEV Community · dev.to