Skip to content

0.77.0

Choose a tag to compare

@antonrh antonrh released this 28 Jul 07:46
· 69 commits to main since this release

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

  • Add lazy dependency references via container.ref() by @antonrh in #304

Full Changelog: 0.76.0...0.77.0