Enterprise Software Engineering with C# and .NET: Architecture, Design Patterns, and AI-Enabled Systems · HIT

Week 4   Part II · API and Persistence

ASP.NET Core Web API

Instructor lesson plan: lecture (2 h) and practice (2 h).

Learning objectives

Tools this week

ASP.NET CoreSwagger / OpenAPIFluentValidationProblemDetails

🎓Lecture · 2 hours

0:00-0:1515 minHTTP and API design recapResources, verbs, status codes, idempotency, and JSON contracts.
0:15-0:4025 minASP.NET Core request pipeline
  • Program.cs, middleware order, routing, endpoint selection.
  • Dependency injection and lifetime choices.
0:40-1:0525 minControllers and Minimal APIsWhen each style is appropriate and how to keep the API layer thin.
1:05-1:1510 minSwagger and OpenAPIAPI documentation as a contract with clients.
1:15-1:2510 minBreak
1:25-1:5025 minDTOs and validation
  • Request and response models versus domain entities.
  • Validation boundaries and error shapes.
1:50-2:0010 minProject previewFirst project endpoints needed for the proposal presentation.
Common misconception to confront.

Students often think: the controller is where the business logic goes.
Set it straight: controllers translate HTTP into application calls. Business behavior belongs behind the API layer.

Check for understanding
Why use DTOs instead of returning EF entities?
DTOs protect the API contract, prevent over-posting, hide persistence details, and let the domain evolve independently.
Where does middleware run?
In the request pipeline, before and after endpoint execution depending on order and whether it calls the next component.
Key takeaways.

📚Reading & resources

💻Practice · 2 hours

0:00-0:2020 minCreate API projectAdd ASP.NET Core API project to the solution and run Swagger locally.
0:20-0:5535 minFirst endpoints
  • Create list, get-by-id, and create endpoints for a core resource.
  • Map DTOs to application commands or service calls.
0:55-1:1015 minValidationAdd request validation and inspect failure responses.
1:10-1:2010 minBreak
1:20-1:5030 minOpenAPI reviewTeams review each other's API contract and name one ambiguity.
1:50-2:0010 minProject-integration briefPrepare API screenshots and endpoint list for Proposal Presentation.

Project integration (this week)

PreviousWeek 3: SOLIDNextWeek 5: Proposal Presentations and EF Core