Lesson 26 / 26
Revision: Cheat Sheet and Self-Check
Review the commands, concepts and common exam questions from the whole course.
Cheat sheet
CLI: new, run, build, test, publish. Pipeline: middleware order matters. DI: transient, scoped (per request), singleton. EF Core: DbContext, migrations, AsNoTracking, avoid N+1. Security: validate input, ProblemDetails, JWT with HTTPS. Ship: multi-stage Dockerfile, health checks, measure first.
Questions interviewers ask
Be ready to explain: the difference between the SDK and runtime, how middleware order affects behaviour, why a singleton must not hold a scoped service, how async/await frees threads, and how you would find and fix an N+1 query.
Quick check: A singleton service needs a DbContext. What is the right fix?
- Make DbContext a static field
- Inject IServiceScopeFactory or DbContextFactory and create a scope per use
- Register everything as singleton
- Disable scope validation
Answer
Inject IServiceScopeFactory or DbContextFactory and create a scope per use — Creating a short-lived scope or context per operation avoids the captive dependency and keeps DbContext non-shared.
Quick check: Your API returns 500 for bad user input. What is the best change?
- Catch the exception and return 200
- Log nothing
- Validate input and return 400 with ProblemDetails
- Restart the server
Answer
Validate input and return 400 with ProblemDetails — Client mistakes are 4xx responses; a 500 should mean a real server fault.
Quick check: Which statement about async/await is correct?
- It creates a new thread for every await
- It lets a thread serve other work while waiting for I/O
- It makes CPU-bound code faster
- It must be avoided in web apps
Answer
It lets a thread serve other work while waiting for I/O — `await` releases the thread during I/O waits. It does not speed up CPU-bound work.