agentleFS
zdanovichnickzdanovichnick/dotnet-pilot/skills/lean-dotnet/SKILL.md

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.

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
  1. Very specific:

    An installed package does it: Check the .csproj and Directory.Packages.props first.

    line 33
  2. Very specific:

    No wrapper that only forwards calls, no factory with one product, no options class nobody sets, no "for later" overloads.

    line 71

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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:

  1. Does it need to exist? Skip options, flags and flexibility nobody asked for, and name what you skipped in one line of the report.
  2. The codebase already has it — a helper, base endpoint, extension method, Result type, house validator. Use it the way its neighbours do.
  3. The BCL or ASP.NET Core ships it (table below). Unless the project has its own version; the house version wins.
  4. An installed package does it. Check the .csproj and Directory.Packages.props first. Never add a NuGet package for a few lines of code.
  5. 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 middlewareAddRateLimiter + RequireRateLimiting (Microsoft.AspNetCore.RateLimiting, .NET 7+)
Retry / timeout / circuit breaker around HttpClientAddStandardResilienceHandler() (Microsoft.Extensions.Http.Resilience) — see resilience
A cache wrapper with stampede lockingHybridCache (.NET 9+) or AddOutputCache — see caching
Request DTO validation in minimal APIsDataAnnotations + builder.Services.AddValidation() (.NET 10)
A custom error envelopeAddProblemDetails() + IExceptionHandler (.NET 8+) — see error-handling
Config binding and checksAddOptions<T>().Bind(...).ValidateDataAnnotations().ValidateOnStart()
A "now" abstractionTimeProvider (.NET 8+); FakeTimeProvider in tests
A dictionary of strategies keyed by nameKeyed services: AddKeyedScoped<T>("key") + [FromKeyedServices] (.NET 8+)
A timer loop in a hosted serviceBackgroundService + PeriodicTimer
A producer/consumer queueSystem.Threading.Channels.Channel<T>
Guard clausesArgumentNullException.ThrowIfNull, ArgumentException.ThrowIfNullOrWhiteSpace, ArgumentOutOfRangeException.ThrowIfNegative
Group-and-count, batchingLINQ CountBy / AggregateBy (.NET 9+), Chunk, DistinctBy
Process tasks as they finishTask.WhenEach (.NET 9+)
Sortable IDsGuid.CreateVersion7() (.NET 9+)
URL-safe Base64System.Buffers.Text.Base64Url (.NET 9+)
A lock objectSystem.Threading.Lock (.NET 9+)
Secure random tokensRandomNumberGenerator.GetHexString / GetInt32 — never Random
Health endpointAddHealthChecks() + MapHealthChecks("/health")
JSONSystem.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 DbContext duplicates what DbSet<T> already is. Add one only when the codebase already has the pattern; never introduce it alongside direct DbContext use.
  • 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 CancellationToken flow.

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 out

Name 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.