Usage with Django

Django can load some modules multiple times which can lead to
InjectorException: Injector is already configured. You can use configure_once which
is guaranteed to run only once when the injector is absent:

import inject
inject.configure_once(my_config)

Testing

In tests use inject.clear_and_configure(callable) to create a new injector on setup,
and optionally inject.clear() to clean up on tear down:

Keys

Why no scopes?

I’ve used Guice and Spring in Java for a lot of years, and I don’t like their scopes.
python-inject by default creates objects as singletons. It does not need a prototype scope
as in Spring or NO_SCOPE as in Guice because python-inject does not steal your class
constructors. Create instances the way you like and then inject dependencies into them.

Other scopes such as a request scope or a session scope are fragile, introduce high coupling,
and are difficult to test. In python-inject write custom providers which can be thread-local,
request-local, etc.