ASP.NET Core from the ground up
Setting up a production-ready ASP.NET Core API step by step — hosting, DI, configuration, security, errors and documentation.
- Program.cs and the hosting model — what those ten lines actually doWebApplication.CreateBuilder sets up configuration, logging, DI and Kestrel before your first line of code runs. What it does for you, what changed since Startup.cs, and how to keep Program.cs readable when the API grows.
- Service registration and DI lifetimes — without the startup of hellSingleton, scoped, transient, captive dependencies, and a Program.cs with 150 AddScoped lines nobody understands. How I structure registrations per feature, and how to let the container catch lifetime bugs before production does.
- Configuration and the Options pattern — fail at startup, not at 3 a.m.Settings that are read with magic strings, validated nowhere and discovered missing on the first request that needs them. How configuration layering works, when to use IOptions, IOptionsSnapshot or IOptionsMonitor, and how ValidateOnStart turns typos into startup failures.
- User secrets and client secrets — and why neither belongs in your repoUser secrets are not encrypted, client secrets expire on a Friday, and the appsettings.json in your Git history still contains last year's password. Where secrets should live during development and in production, and how to stop needing most of them.
- Authentication basics with JWT bearer tokens — secure by defaultOne forgotten [Authorize] attribute and an endpoint is public. How JWT bearer validation works in ASP.NET Core, why I make authentication the fallback policy, how to check scopes properly, and how to test it all without a real identity provider.
- CORS done right — including preflight requestsA wildcard origin plus AllowCredentials, a hand-written OPTIONS middleware and a platform CORS setting that silently overrides the app. What CORS actually protects, how preflight works, and the setup that avoids the usual traps.
- Security filters — rejecting what your API never asked forASP.NET Core silently ignores query parameters your endpoint doesn't declare. A small filter that rejects them turns scanner noise into a visible security signal. Why it's defense in depth and not injection protection, and how to build it for controllers and minimal APIs.
- Global error handling with ProblemDetails — one error format for the whole APIFive endpoints, five error formats, and a stack trace in production. How to set up IExceptionHandler and ProblemDetails so every error looks the same, exceptions map to the right status codes, and production responses don't help attackers.
- Error logging — log once, in one place, at the right levelThe same exception logged four times on its way up, a 404 at Error level waking someone at night, and the one real failure buried in the noise. How to separate error logging from error handling, pick log levels by exception category and test that it works.
- Setting up Swagger / OpenAPI — Microsoft.AspNetCore.OpenApi or Swashbuckle?Since .NET 9 the templates no longer ship Swashbuckle, and upgraded projects suddenly render "Unable to render this definition". What changed, how to set up the built-in OpenAPI generator with versioning, security and per-stage metadata, and when Swashbuckle is still the better fit.
- A health endpoint that tells the truthA /health endpoint that always returns Healthy is worse than none, and one that checks every dependency can restart your whole fleet when one database hiccups. Liveness vs. readiness, the built-in health checks, and what to check where.
- Controllers vs. minimal APIs — it's about structure, not syntaxMinimal APIs were rejected as "unmaintainable for large projects", and later a similar team built their whole endpoint structure on them. What actually differs between controllers and minimal APIs in 2026, and the per-feature structure that makes either one scale.
- Why there is no try/catch in my endpointsEvery endpoint wrapped in try/catch, every catch returning BadRequest with a different body. Why that pattern hurts, what replaces it, the few places where try/catch is still right, and how to make the rule something the build checks.
- Automatic dependency registration — scanning, Scrutor and source generatorsWriting an Add extension for every service gets old, and scanning the assembly feels like magic until it registers the wrong thing. The options for automatic registration — reflection, Scrutor, graph walking, source generators — and the trade-offs that decide which one I use.