dotnet

Guides C# and ASP.NET Core development covering EF Core, dependency injection, testing, and Azure SDK integration.

Updated Aug 2, 2026
One-click install
npx skills add https://github.com/leonardoacosta/skills --skill dotnet-leonardoacosta
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet
Source: https://github.com/leonardoacosta/skills/tree/main/dotnet-kit/skills/dotnet
Command: npx skills add https://github.com/leonardoacosta/skills --skill dotnet-leonardoacosta

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Backend work in .NET repositories often suffers from inconsistent patterns: mis-lifetimed DI registrations, socket-leaking HttpClient usage, N+1 EF Core queries, swallowed exceptions, and fragile test setups. This Skill provides a single authoritative set of conventions for C# / ASP.NET Core projects so engineers apply the correct pattern for each task. ## Core Features & Use Cases - EF Core data layer guidance: DbContext registration, AsNoTracking queries, split queries, soft-delete filters, and a safe migrations workflow including idempotent SQL scripts for production deploys. - DI, HttpClient, and configuration patterns: Correct service lifetimes, IHttpClientFactory typed clients with resilience handlers, DefaultAzureCredential managed-identity wiring, and validated IOptions<T> binding. - API and testing standards: Controller vs minimal API selection, ProblemDetails error handling, API versioning, xUnit structure, WebApplicationFactory integration tests, and Testcontainers real-database testing. - Use Case: When building a headless ASP.NET Core API on .NET 8/9/10 backed by SQL Server and Azure services, load this Skill to route each task (data, services, endpoints, tests) to the right reference and avoid classic traps like captive dependencies or in-process migration race conditions. ## Quick Start Ask the agent to apply the dotnet skill conventions while implementing a new EF Core-backed endpoint with integration tests in your ASP.NET Core repository.

Frequently Asked Questions about dotnet

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure integration tests for an ASP.NET Core API?

Use WebApplicationFactory<TEntryPoint> to boot the real app in-memory and exercise the full middleware pipeline with an HttpClient. Override services via ConfigureTestServices, and point the factory at a real database from Testcontainers rather than the EF in-memory provider.

How do I avoid N+1 queries and slow reads in EF Core?

Use AsNoTracking on read-only queries, project with Select into DTOs, and use Include or AsSplitQuery for related collections instead of per-row queries. Push Where filters into the database query rather than filtering with LINQ-to-objects after ToList.

Should I use controllers or minimal APIs in ASP.NET Core?

Choose controllers when you need filters, rich model binding, or the repo already uses them; choose minimal APIs for small services with few endpoints. Match the existing repository style and never mix both for the same resource.

Why does injecting a scoped service into a singleton cause bugs?

The singleton captures the first request's scoped instance and reuses it for the app's lifetime, producing stale DbContext data and cross-request data bleed. Inject IServiceScopeFactory into the singleton and create a scope per unit of work instead.

Can I run EF Core migrations automatically at app startup?

Calling Database.Migrate() at startup risks replica races, crash-loops, and coupled schema-deploy timing. Prefer a one-shot pre-deploy migration job using dotnet ef database update or an idempotent SQL script run once by the pipeline.

How do I authenticate to Azure services from C# without secrets?

Use DefaultAzureCredential from Azure.Identity, which works with managed identity in App Service and Azure CLI locally with no code change. Register SDK clients like SecretClient or DataLakeServiceClient as singletons and never use account keys or connection-string secrets.