FastAPI - Dependency InjectionWhich method must a class implement to be used as a dependency in FastAPI?A__init__B__call__CdependencyDrunCheck Answer
Step-by-Step SolutionSolution:Step 1: Recall FastAPI dependency requirementsFastAPI requires the class to be callable, which means it must implement the __call__ method.Step 2: Match method names to this requirementOnly __call__ makes the class instance callable; __init__ is for initialization, others are invalid.Final Answer:__call__ -> Option BQuick Check:Callable class = __call__ method [OK]Quick Trick: Class must be callable via __call__ method [OK]Common Mistakes:MISTAKESChoosing __init__ instead of __call__Using random method names like 'run'Confusing dependency with method name
Master "Dependency Injection" in FastAPI9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More FastAPI Quizzes Authentication and Security - Protected routes - Quiz 5medium Database Integration - Database session management - Quiz 14medium Database Integration - Connection pooling - Quiz 4medium Dependency Injection - Path operation dependencies - Quiz 14medium Error Handling - Why error handling ensures reliability - Quiz 6medium Error Handling - Custom error response models - Quiz 7medium File Handling - File validation (size, type) - Quiz 6medium File Handling - Serving static files - Quiz 7medium File Handling - Serving static files - Quiz 10hard Middleware and Hooks - Lifespan context manager - Quiz 4medium