In the application factory pattern, where should extensions like SQLAlchemy be initialized?
easy📝 Conceptual Q2 of 15
Flask - Ecosystem and Patterns
In the application factory pattern, where should extensions like SQLAlchemy be initialized?
AOutside the factory function without binding to app
BInside the factory function after creating the app
CInside the factory function before creating the app
DOnly in the main script, never in the factory
Step-by-Step Solution
Solution:
Step 1: Recall extension initialization best practice
Extensions should be created outside the factory function without app binding, then initialized with app inside the factory.
Step 2: Match options to this pattern
Outside the factory function without binding to app correctly states extensions are created outside without binding. Inside the factory function after creating the app is wrong because initialization happens inside, but creation is outside. Options C and D are incorrect.
Final Answer:
Outside the factory function without binding to app -> Option A