Repository navigation
0.77.0
Lazy references
container.ref() returns a lazy reference to a dependency. It behaves like the dependency itself and resolves on first attribute access, so it can live at module level:
db = container.ref(Database)
def handler() -> None:
db.execute("delete * from users")The reference asks the container for the current instance every time, so an override applies to code that already holds it:
with container.test_mode(), container.override(Database, db_mock):
handler()Singletons are cached inside the reference. The cache is dropped whenever the container state changes.
Transient and asynchronous dependencies are rejected up front. A reference needs an instance to refer to, and it resolves synchronously.
See References.
What's Changed
Full Changelog: 0.76.0...0.77.0