Mode d’emploi
- Copiez la commande et examinez le paquet avant de l’installer dans votre environnement agent.
- Consultez le document original pour les outils, identifiants et environnements requis.
- Décrivez les entrées et le livrable souhaité ; comparez la sortie aux sources.
npx skills add https://github.com/victorzhuk/skills --skill z-dotnet-coreAvant de commencer
- L’installation n’inclut ni abonnement au modèle, ni quota API, ni accès aux fichiers.
- Étoiles et installations reflètent l’activité, pas un test indépendant de qualité ou de sécurité.
Rendu depuis le dépôt source en conservant titres, exemples, code, tableaux, liens et images.
.NET core
Default to minimal APIs for a new small service, controllers only where the codebase already committed to them — don't migrate an inherited controller app just to match a green one.
Target framework
- Select a supported LTS from Microsoft's current support policy for new services. Preserve the target of an inherited application unless an upgrade is in scope.
- verify against the actual
global.json/.csprojTargetFrameworkbefore assuming a version — an inherited codebase may sit on an out-of-support release
API style
- minimal APIs (
MapGet/MapPostonWebApplication) for small, focused services — less ceremony, faster to read top to bottom - controllers where the codebase already has them — don't rewrite a working controller-based API to minimal APIs on style preference alone
- nullable reference types enabled (
<Nullable>enable</Nullable>) with warnings treated as errors — this is what makes anulla compile-time signal instead of a runtime surprise
Dependency injection
- Use constructor injection for services and supported handler-parameter injection for minimal APIs. Do not hide dependencies behind
IServiceProvider.GetServicein business logic. - register lifetimes deliberately:
Scopedfor anything touching aDbContextor per-request state,Singletononly for genuinely stateless or thread-safe services,Transientfor cheap short-lived instances
EF Core discipline
- review every migration before it ships — a generated migration can silently drop a column or add a non-nullable one without a default on a populated table
AsNoTracking()on read-only queries — skips change-tracking overhead for data that's never saved back- no lazy-loading surprises: either disable lazy loading and
Include()explicitly, or know exactly which navigation properties trigger N+1 queries on access - LINQ readable over clever — a query that reads like the SQL it produces is easier to review than one showing off
Aggregate/SelectManychains
Async
- Keep asynchronous I/O asynchronous through the endpoint. Blocking on
.Resultor.Wait()can cause thread-pool starvation; ASP.NET Core does not install the classic ASP.NET synchronization context. - thread a
CancellationTokenthrough to DB/HTTP calls that support it, sourced from the request's own token
Testing
- xUnit as the default test framework
WebApplicationFactory<T>for API-level tests against the real DI graph and middleware pipeline, not just isolated handler unit tests
Do not
- grow god controllers — a controller accumulating unrelated endpoints is a decomposition signal, not a place to keep adding
[HttpPost]methods - sync-over-async (
.Result,.Wait(),.GetAwaiter().GetResult()on a hot path) — thread-pool starvation and deadlocks follow - use
DateTime.Nowfor anything that becomes business logic or gets tested — useDateTime.UtcNow, or injectTimeProvider(built into .NET 8+) so tests can control time - catch
Exceptionbroadly at a layer that isn't the outermost error boundary — it swallows bugs a narrower catch or the framework's own exception handling would surface
Verify
dotnet build -warnaserror- Use the existing test wrapper with a whole-process deadline and the selected runner's supported timeout and parallelism limits; see [[z-testing-strategy]]. Discover the runner before choosing flags.
dotnet format --verify-no-changes

