Bird
0
0

Which method must a class implement to be used as a dependency in FastAPI?

easy📝 Syntax Q12 of 15
FastAPI - Dependency Injection
Which method must a class implement to be used as a dependency in FastAPI?
A__init__
B__call__
Cdependency
Drun
Step-by-Step Solution
Solution:
  1. Step 1: Recall FastAPI dependency requirements

    FastAPI requires the class to be callable, which means it must implement the __call__ method.
  2. Step 2: Match method names to this requirement

    Only __call__ makes the class instance callable; __init__ is for initialization, others are invalid.
  3. Final Answer:

    __call__ -> Option B
  4. Quick Check:

    Callable class = __call__ method [OK]
Quick Trick: Class must be callable via __call__ method [OK]
Common Mistakes:
MISTAKES
  • Choosing __init__ instead of __call__
  • Using random method names like 'run'
  • Confusing dependency with method name

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes