lean-dotnet
Skill5 starsChanged 22 days agoMITView on GitHub
The smallest complete change in a .NET solution — the reuse ladder (codebase, BCL and ASP.NET Core built-ins, installed packages, then new code), what the framework already ships, the `shortcut:` comment for a known limit, and what is never cut.
In this repository19 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- api-contractSkill
- aspnet-api-patternsSkill
- authenticationSkill
- cachingSkill
- clean-architectureSkill
- convention-learnerSkill
- dddSkill
- dotnet-project-initSkill
- ef-core-patternsSkill
- error-handlingSkill
- loggingSkill
- modern-csharpSkill
- opentelemetrySkill
- react-typescriptSkill
- resilienceSkill
- testing-dotnetSkill
- ui-ux-designSkill
- vertical-sliceSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 33
An installed package does it: Check the .csproj and Directory.Packages.props first.
- Very specific: line 71
No wrapper that only forwards calls, no factory with one product, no options class nobody sets, no "for later" overloads.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Lean .NET
The best code is the code nobody has to write. Be lazy about the solution, never about the change:
finish every place the change must reach — callers, DI registration, appsettings*.json, the
migration, the tests your change breaks.
Before you write
List the places the change must reach. For a signature change, that is every caller
(mcp__roslyn__find_callers or find_references), every implementation of the interface
(find_implementations), and the registration. That list is the scope; features nobody asked for
are not.
Bug fix: find every caller of the function you touch first, then fix the root cause once in the shared code. A guard added in one caller leaves the others broken.
The reuse ladder
Take the first rung that fully works:
- Does it need to exist? Skip options, flags and flexibility nobody asked for, and name what you skipped in one line of the report.
- The codebase already has it — a helper, base endpoint, extension method,
Resulttype, house validator. Use it the way its neighbours do. - The BCL or ASP.NET Core ships it (table below). Unless the project has its own version; the house version wins.
- An installed package does it. Check the
.csprojandDirectory.Packages.propsfirst. Never add a NuGet package for a few lines of code. - Otherwise, the minimum code that passes the test.
Between options of equal size, take the one that is correct on the edge cases (empty, null,
default, time zones, cancellation).
Already in the framework
| Before you write… | Use |
| Rate limiting middleware | AddRateLimiter + RequireRateLimiting (Microsoft.AspNetCore.RateLimiting, .NET 7+) |
Retry / timeout / circuit breaker around HttpClient | AddStandardResilienceHandler() (Microsoft.Extensions.Http.Resilience) — see resilience |
| A cache wrapper with stampede locking | HybridCache (.NET 9+) or AddOutputCache — see caching |
| Request DTO validation in minimal APIs | DataAnnotations + builder.Services.AddValidation() (.NET 10) |
| A custom error envelope | AddProblemDetails() + IExceptionHandler (.NET 8+) — see error-handling |
| Config binding and checks | AddOptions<T>().Bind(...).ValidateDataAnnotations().ValidateOnStart() |
| A "now" abstraction | TimeProvider (.NET 8+); FakeTimeProvider in tests |
| A dictionary of strategies keyed by name | Keyed services: AddKeyedScoped<T>("key") + [FromKeyedServices] (.NET 8+) |
| A timer loop in a hosted service | BackgroundService + PeriodicTimer |
| A producer/consumer queue | System.Threading.Channels.Channel<T> |
| Guard clauses | ArgumentNullException.ThrowIfNull, ArgumentException.ThrowIfNullOrWhiteSpace, ArgumentOutOfRangeException.ThrowIfNegative |
| Group-and-count, batching | LINQ CountBy / AggregateBy (.NET 9+), Chunk, DistinctBy |
| Process tasks as they finish | Task.WhenEach (.NET 9+) |
| Sortable IDs | Guid.CreateVersion7() (.NET 9+) |
| URL-safe Base64 | System.Buffers.Text.Base64Url (.NET 9+) |
| A lock object | System.Threading.Lock (.NET 9+) |
| Secure random tokens | RandomNumberGenerator.GetHexString / GetInt32 — never Random |
| Health endpoint | AddHealthChecks() + MapHealthChecks("/health") |
| JSON | System.Text.Json, unless the project already uses Newtonsoft |
Abstractions: what is lean in .NET
- An interface with one implementation is not automatically waste here. A port in Application
implemented in Infrastructure, or an interface that a test substitutes, is the layer rule
(
clean-architecture). It is waste when nothing substitutes it and no layer boundary needs it. - A generic repository over
DbContextduplicates whatDbSet<T>already is. Add one only when the codebase already has the pattern; never introduce it alongside directDbContextuse. - No wrapper that only forwards calls, no factory with one product, no options class nobody sets,
no "for later" overloads. Keep the structure the solution already has: its layers, folders and
registration style (
convention-learner). - Code you move or merge keeps its validation, error handling and
CancellationTokenflow.
Known limits: the shortcut: comment
A deliberate simplification with a known ceiling gets one comment in this form, and it is one of the few comments worth writing:
// shortcut: in-process cache, per instance; move to HybridCache with Redis when we scale outName the limit and the trigger to revisit it. A reviewer treats a shortcut: line as a recorded
decision, not a finding, unless the change already crosses the limit it names. Find them all with
git grep -n "// shortcut:" -- "*.cs".
Never cut
Validation at trust boundaries, error handling that prevents data loss, authorization, transactions
around multi-write operations, CancellationToken on request paths, the DI registration, the
migration, and anything the brief asked for. New logic with a branch, a loop, a parser, money or
security leaves one test that fails when it breaks.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

