Module 07 Knowledge Check
5 questions. Pass mark 4 out of 5. Answer every question before checking the answer key below, then retry after reading the feedback.
1. A dependency differs from a helper function called in the handler because…
- A. it is faster
- B. it runs before the handler, appears in the docs and cannot be forgotten
- C. it can be async
- D. it is required by FastAPI
2. An expensive object should be…
- A. created per request
- B. built once behind a cached dependency and injected
- C. a module-level global
- D. created in the handler
3. A check that guards but supplies nothing belongs…
- A. in the handler signature
- B. in the route decorator's dependencies list
- C. in middleware only
- D. in the service
4. dependency_overrides lets a test…
- A. skip validation
- B. run the whole request path with the costly part replaced
- C. change the route
- D. bypass authentication automatically
5. Business logic in a dependency…
- A. is a clean pattern
- B. becomes reachable only through HTTP
- C. improves testability
- D. is required for services
---
Answer Key and Explanations
Check these only after attempting every question.
1. B - it runs before the handler, appears in the docs and cannot be forgotten
The helper is one an author can forget on the endpoint added under time pressure.
2. B - built once behind a cached dependency and injected
A module-level global cannot be replaced in a test.
3. B - in the route decorator's dependencies list
The handler should not take a parameter it never uses.
4. B - run the whole request path with the costly part replaced
That is the payoff for injecting the model rather than importing it.
5. B - becomes reachable only through HTTP
Which is exactly what the service layer exists to prevent.
Practical Check
Apply this module to your own work: complete the module activity for *Dependency Injection for Shared Logic and Settings*, then write one sentence naming what your result shows and one naming what it does not.
Strong Answer Pattern
A strong answer names the task, the evidence used, the check performed, and the remaining limitation. It avoids "proved", "guaranteed", or "always" unless the evidence genuinely supports it.
