anantbhandarkar/make-it-right/mir-backend-dotnet-aspnetcore
Claude Code and agent skill by anantbhandarkar/make-it-right
- community
Checking that the SKILL.md file is still in the repository.
Make It Right (ASP.NET Core module). ASP.NET Core 10 + Minimal APIs + EF Core 10 footguns. Covers: DI lifetime errors (AddDbContext Scoped vs singleton capture, IHttpContextAccessor caveats), middleware pipeline ORDER (UseRouting -> UseAuthentication -> UseAuthorization -> UseAntiforgery -> endpoints; wrong order silently disables auth), model binding overposting onto EF entities and why [Bind] does NOT work on JSON bodies, response DTO discipline against field leakage, EF Core N+1 and the EF Core 10 parameterized-collection translation change, ExecuteUpdate/ExecuteDelete bypassing the change tracker, object-level authorization (IDOR via a valid token, no resource check), .NET 10 AddValidation, the non-short-circuiting antiforgery middleware, and CORS credentials misconfiguration. Chains: mir-backend -> mir-backend-dotnet (CLR runtime) -> this, which adds only ASP.NET Core / EF Core library mechanics. TRIGGER only when the .NET backend stack uses ASP.NET Core or Minimal APIs — building, reviewing, or debugging a controller, endpoint, middleware, EF Core query, or migration. SKIP for CLR-level concerns (mir-backend-dotnet), for Blazor WebAssembly, standalone gRPC, Orleans, WCF, and Azure Functions (each gets its own mir-backend-dotnet-<framework> module), and for every non-.NET runtime.
Install
npx vskill@latest install anantbhandarkar/make-it-right/mir-backend-dotnet-aspnetcoreSKILL.md
The same SKILL.md was published earlier as anantbhandarkar/make-it-right/mir-backend-dotnet-aspnetcore.
/mir-backend-dotnet-aspnetcore · Make It Right (ASP.NET Core)
Bottom tier of the chain: mir-backend (generic gates) → mir-backend-dotnet (CLR runtime model) → this (ASP.NET Core / EF Core / Minimal API library mechanics). Run the gates first; load the .NET runtime tier for async model, DI lifetime theory, and thread-pool concerns; reach for this at Gate 5 (design mechanics), Gate 6 (implementation), and Gate 7 review. Runtime-level concerns (sync-over-async deadlock, ConfigureAwait(false), ValueTask, IDisposable, CancellationToken propagation, captive dependency theory) live in `mir-backend-dotnet` — not here.
Stack assumed (verified 13 Aug 2026): ASP.NET Core 10 (controllers or Minimal APIs) · EF Core 10 · SQL Server / PostgreSQL · Microsoft.EntityFrameworkCore.Design migrations. Current patch is 10.0.11 (11 Aug 2026).
Version notes that change what you should write:
- EF Core 10 requires .NET 10. There is no EF Core 10 on
net8.0. A project stuck onnet8.0/net9.0is stuck on EF Core 8/9, and both of those runtimes leave support on 10 Nov 2026 (seemir-backend-dotnet). - EF Core 10 changed how parameterized collections translate — see footgun 4. This is the one upgrade change most likely to show up as a production latency regression rather than a compile error.
- `ExecuteUpdateAsync` now takes a plain lambda instead of an expression tree in EF Core 10. Code that composed
Expression<Func<SetPropertyCalls<T>, SetPropertyCalls<T>>>by hand no longer compiles; rewrite it as ordinaryif/loop statements inside the lambda. EachSetPropertyselector is still expression-based and must translate to SQL.
If the project uses Dapper or a different ORM, note the divergence before applying EF-specific guidance.
The ASP.NET Core footguns AI walks into most
1. DI lifetimes in practice — AddDbContext is Scoped; singletons must not capture it
AddDbContext<T>() registers DbContext as Scoped (one instance per HTTP request). Inject it into a Singleton — a hosted service, a cache, an event handler — and the captive-dependency bug from the runtime tier becomes one shared context serving every request: cross-request data bleed plus InvalidOperationException: A second operation was started on this context.
`IHttpContextAccessor` caveat: it is Singleton but reads Scoped HttpContext. Safe in middleware and request-scoped code; inside a background service or event handler it returns null. It is not a general-purpose context bag.
2. Middleware ORDER is the pipeline contract
ASP.NET Core middleware runs in registration order, and nothing warns you about a wrong order. Be precise about the failure: UseAuthorization() before UseAuthentication() makes authorization evaluate an anonymous principal, so legitimate callers get 401/403 — it is broken, not a bypass. The orders that genuinely weaken security are UseCors() in the wrong place and UseAntiforgery() before auth.
Other ordering traps:
UseCors()must come beforeUseAuthentication/UseAuthorizationand the endpoint mappings to emit CORS headers on preflight.- `UseAntiforgery()` must come after `UseAuthentication` and `UseAuthorization`, so form data is never read for an unauthenticated caller.
WebApplicationBuilderadds it automatically in the right place; if you call it explicitly, you own the position. UseExceptionHandler()/UseHsts()/UseHttpsRedirection()belong at the very top (before any business middleware) so they catch all exceptions and redirect correctly.- Custom middleware that reads
HttpContext.Usermust come afterUseAuthentication. - `MapStaticAssets()` (ASP.NET Core 9+) is an endpoint, not middleware. It participates in routing, so it goes where the other
Map*calls go — not whereUseStaticFiles()used to sit aboveUseRouting(). It only serves assets known at build/publish time (with build-time compression and content-hash fingerprinting). Files written to disk after deployment, or served from embedded resources, still needUseStaticFiles(). UseRateLimiter()must come afterUseRouting()if any policy is attached per-endpoint, otherwise the endpoint metadata is not resolved yet and the policy silently does not apply.
3. Model binding overposting / mass assignment — never bind straight to EF entities
Binding a request body directly to an EF entity lets a client set any property the model exposes, including IsAdmin, Role, TenantId, OwnerId, or audit timestamps:
`[Bind]` / `[BindNever]` do NOT protect a JSON API. This is the most common wrong fix, and AI emits it confidently. Microsoft's docs state [Bind] "does not affect input formatters" — those attributes are read by the MVC model binding system, which handles form and query values. A [FromBody] parameter is deserialized by an input formatter (System.Text.Json), and binding-source attributes on its properties are ignored. [Bind("Name,Email")] on a JSON DTO is a no-op that reads like a control.
| Mechanism | Where it applies | Notes | |
|---|---|---|---|
| A separate request record with only the writable fields | everywhere | The real fix. If the type has no IsAdmin property, nothing can set it. | |
JsonSerializerOptions.UnmappedMemberHandling = JsonUnmappedMemberHandling.Disallow | JSON bodies | Rejects payloads containing undeclared members (400 instead of silent ignore). Also per-type via [JsonUnmappedMemberHandling]. | |
[JsonIgnore] on the sensitive property | JSON bodies and responses | Serializer-level. Blunt — removes the property from output too. | |
[Bind] / [BindNever] / [BindRequired] | form and query binding only | Fine for Razor Pages/MVC form posts. Useless for [FromBody]. |
[JsonExtensionData] on a DTO collects every unmapped member into a dictionary and reintroduces the whole problem.
Never return the EF entity directly — use a response DTO. Otherwise you leak password hashes and internal flags, and the response shape changes with whichever navigation properties an earlier query happened to load.
4. EF Core N+1 — lazy loading raises in async, doesn't just degrade performance
Lazy-loading proxies issue one synchronous query per navigation access — they do not become async just because the surrounding method is. Inside a loop that is N+1; after the DbContext is disposed the navigation cannot load at all and you get InvalidOperationException. Both forms are defects:
Rules:
- `Include()` for full entity graphs you need to mutate.
- `Select()` to DTO for read-only endpoints — eliminates N+1 at the query level and avoids loading unnecessary columns.
- `AsNoTracking()` on read-only queries to skip the identity-map overhead (significant under load).
- Avoid
ToList()+ LINQ-to-objects filtering — this pulls the entire table into memory. Filter in the query (Where,Take,Skip). - `Include()` on two or more collection navigations produces a cartesian product — rows multiply, and a "slow query" turns into gigabytes of duplicated data over the wire. Use
AsSplitQuery()(separate SELECT per collection, no cross-collection consistency inside the query) or project to a DTO.
EF Core 10 changed collection parameter translation — an upgrade can regress query plans
Where(b => ids.Contains(b.Id)) has been translated three different ways in three releases. EF Core 8 and 9 sent the whole collection as one JSON parameter (OPENJSON on SQL Server). EF Core 10 defaults to multiple scalar parameters — WHERE [b].[Id] IN (@ids1, @ids2, @ids3) — padded up to a bucket size so the plan cache does not fill with one entry per collection length. Better for small collections (the optimizer gets real cardinality), worse for large ones (wire overhead and a hard provider parameter limit). The upgrade does not break the build; it changes the SQL, so it shows up as latency.
TranslateParameterizedCollectionsToConstants is obsolete — UseParameterizedCollectionMode replaces it.
ExecuteUpdate / ExecuteDelete skip everything the change tracker does
They issue one UPDATE/DELETE directly. That is why they are fast, and why they are dangerous in code that relies on SaveChanges behaviour:
- No `SaveChangesAsync` interceptors fire — audit columns, save-time soft-delete, outbox writes, and domain events all silently do not run.
- No optimistic concurrency check. A
[Timestamp]/rowversionproperty is not compared, so a lost update is not detected. - Loaded entities go stale. The tracked copy still holds the old values; a later
SaveChangesAsynccan write them back. - They execute immediately, outside the current `DbContext` transaction unless you opened one with
db.Database.BeginTransactionAsync(ct).
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/mir-backend-dotnet-aspnetcore/SKILL.md
Popularity
- Repository stars
- 15
- 7-day trend score
- 14
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/anantbhandarkar/make-it-right/mir-backend-dotnet-aspnetcore)