How to avoid a circular import when using python-dependency-injector in a Flask project?

Asked 2 years ago

I'm new to Flask and Python in general. Circular imports are bad - I know that. But how do you avoid them?

Alan Lang

Sunday, July 24, 2022

There are a few ways to avoid a circular import when using python-dependency-injector in a Flask project: 1. Use the @provides decorator to explicitly mark which modules or classes should be injected. 2. Use the injector module directly instead of the @provides decorator. 3. Use a third-party tool such as pydantic to validate the dependencies.





Write an answer...

Cancel

Please follow our  Community Guidelines

Can't find what you're looking for?