Skip to main content
CodeOath
← All posts

.NET Core / Web API71 min total · 19 parts

Building REST APIs with ASP.NET Core: Routing, Middleware, and Dependency Injection

Part 1 of 19 · ~2 min

Overview

Here's the afternoon this whole reference is quietly built around. Two students — Marcus and Yuki — walk up to the same laser cutter at Ridgeline Makerspace at 2:45 on a Tuesday, both holding a confirmation screen on their phone for the same fifteen-minute slot. Bench, the reservation system Dana and Theo built for the makerspace, had accepted both bookings. Not "showed a stale screen that then caught up" — accepted, confirmed, emailed a receipt to each of them, and never once complained. Nobody's request errored. Nobody saw a conflict warning. The staff dashboard that's supposed to show what's booked showed exactly one reservation for that slot, and it happened to be Marcus's, even though Yuki's confirmation had gone out four minutes later.

That's the bug this reference eventually runs all the way to ground — not because a double-booked laser cutter is high-stakes, but because the actual mechanism behind it touches nearly everything that decides how an ASP.NET Core Web API behaves once real traffic hits it: which middleware saw the request and in what order, where a dependency actually came from and how long it's supposed to stick around, and what the framework quietly promises you by default — a promise you can break without technically breaking any rule the compiler enforces.

This reference builds Bench from its first, genuinely simple version through to the one that survives a Tuesday-afternoon rush without repeating that mistake, covering the full path a request takes through ASP.NET Core along the way: the hosting model, the middleware pipeline, routing and model binding, validation, dependency injection and its lifetimes, configuration, EF Core, authentication and authorization, CORS, error handling, filters, versioning, async from top to bottom, and how you actually test any of it once it's built this way. Read it start to finish if you've got the time — every chapter names which version of Bench it's picking up right at the top — or skip straight to whichever piece is actually giving you trouble using the sidebar.