dotnet-architect
Architect-level .NET guidance — solution and namespace layering, DI lifetimes and their bugs, async/await discipline, EF Core usage boundaries, and the hosting, configuration and observability shape of an ASP.NET service. Use when designing or reviewing a .NET backend.
- License 许可
- MIT
- 最近更新
- 2026-11-13
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- dotnet-architect
- license
- MIT
- metadata
- { "crusor-path": "website-architect/backend-development-architect/dotnet-architect", "crusor-domain": "website-architect", "crusor-origin": "original", "crusor-sources": "learn.microsoft.com/aspnet/core; learn.microsoft.com/ef/core; learn.microsoft.com/dotnet/standard/asynchronous-patterns", "crusor-triggers": "dotnet, .net, csharp, asp net core, ef core, dependency injection lifetimes, minimal api", "crusor-verified-on": "2026-10-30" }
- description
- Architect-level .NET guidance — solution and namespace layering, DI lifetimes and their bugs, async/await discipline, EF Core usage boundaries, and the hosting, configuration and observability shape of an ASP.NET service. Use when designing or reviewing a .NET backend.
- compatibility
- .NET 8/9; ASP.NET Core; EF Core
03 SKILL.md 正文
.NET Architect
.NET gives you a container, a lifetime model and an async runtime. Nearly every subtle production bug is a lifetime mistake or a blocked thread.
When to use
- Enterprise services, Windows/Linux mixed estates, Azure-first deployments.
- Strong typing, mature tooling and long support windows matter.
- Existing .NET code or team expertise.
When NOT to use
- Tiny services where a Go binary or a Node function is simpler and cheaper.
Decision 1 — Solution structure
src/Api/ controllers/minimal endpoints, composition root
Application/ use-cases; interfaces only
Domain/ entities, rules, no EF/framework types
Infrastructure/ EF Core, external clients
tests/ per layer
- Dependencies point inward; Domain references nothing.
- One composition root (
Program.cs) wires everything. internalby default; public surface is a contract.
Decision 2 — DI lifetimes (the classic bug)
| Lifetime | Use | Danger |
|---|---|---|
| Singleton | stateless services, caches | capturing scoped services |
| Scoped | per-request: DbContext, unit of work | never in a singleton |
| Transient | lightweight, stateless | pooling pressure |
- A singleton holding a
DbContextis a correctness bug, not a performance tweak. - Validate scopes enabled in development (
ValidateScopes = true) so misuse fails at startup. IHttpClientFactoryfor outbound HTTP; nevernew HttpClient()per request.
Decision 3 — Async discipline
asyncall the way; never.Resultor.Wait()in request paths (deadlocks and thread starvation).CancellationTokenthreaded through every call that touches I/O.Task.WhenAllfor independent work; sequential awaits for dependent work.- Background work:
BackgroundService/queue — not a fire-and-forget task inside a request.
Decision 4 — EF Core boundaries
- Queries in a repository/handler layer;
AsNoTracking()for reads. - Projection (
Select) instead of loading graphs you discard. - N+1:
Includedeliberately, or project; measure query counts in tests. - Migrations are explicit and reviewed;
EnsureCreatedis for tests only. - Keep
DbContextshort-lived (per request/scope); no long-lived caching of entities.
Decision 5 — Hosting and operations
- Configuration:
appsettings+ environment + secret store; validated options. - Health checks split liveness/readiness; graceful shutdown drains requests.
- Structured logging (
ILoggerscopes with correlation id) and OpenTelemetry. - Container images: multi-stage build, non-root, no SDK in the runtime image.
Failure modes at scale
- Singleton capturing
DbContext→ concurrent use exception under load. .Resultin an async controller → thread-pool starvation at peak.- EF queries without projection → 3 MB payloads per request.
- Migrations applied by every instance at boot → race on startup.
- Secrets in
appsettings.jsoncommitted.
Verification receipts
- Lifetime audit: no scoped service captured by a singleton; scope validation on.
- Query-count test on the busiest endpoint (no N+1).
- Cancellation test: client abort stops downstream work.
- Migration applied as a deploy step, once.
- Health-check behaviour with a dependency down.
04 同仓库更多 Skills
interaction-patterns-architect
Architect-level interaction design in code — choosing established patterns over invented ones, feedback and latency behaviour, destructive-action safeguards, navigation and overlay conventions, and the state model behind every interactive surface. Use when a screen has to behave, not just look.
design-system-ops-architect
Architect-level operation of a design system in code — token pipelines and versioning, component API and variant policy, the catalogue as the contract, adoption metrics, and the governance that stops a system from forking into three. Use when a component library must survive several teams.
design-handoff-architect
Architect-level design handoff — what must be specified before implementation starts, tokens over raw values, responsive and content-limit contracts, state matrices, and the review loop that catches drift between design and code. Use when a design is about to become code.
content-microcopy-architect
Architect-level UI content — where strings live, voice and terminology consistency, error and empty-state copy as part of the interface, translation-ready authoring, and the content model a product needs before it multiplies screens. Use when the words in the interface matter as much as the pixels.
ui-ux-implementation-architect
Architect-level direction for turning a design into working UI — the handoff contract, component ownership versus screen-level layout, interaction and state conventions, design QA gates, and the review habits that keep an implementation faithful without frozen pixels. Use before any specific UI implementation skill.
test-strategy-architect
Architect-level test strategy — allocating assertions across unit, integration, contract and end-to-end layers, designing for testability through dependency boundaries, fixture and data strategy, and the flake and coverage policies that keep a suite trustworthy. Use when defining how a codebase is tested.