Skip to main content

Qx dependency-injection container: singleton/scoped/transient, async lifecycle, generic-aware resolution

Project description

qx-di

Async dependency-injection container for the Qx framework. Supports SINGLETON, SCOPED, and TRANSIENT lifetimes with full async lifecycle, generic-aware resolution, and decorator-based registration.

What lives here

  • qx.di.Container — resolves, caches, and scopes dependencies. Supports register_singleton, register_scoped, register_transient, register_instance, and override.
  • qx.di.Scope — per-request child scope. Scoped registrations live exactly as long as their scope.
  • qx.di.LifetimeSINGLETON / SCOPED / TRANSIENT enum.
  • qx.di.singleton / scoped / transient — class decorators that embed registration metadata without touching the class interface.
  • qx.di.scan — discover and register all decorated classes in a package tree.
  • qx.di.injectable — low-level decorator for explicit key/lifetime/factory overrides.

Usage

from qx.di import Container, Scope, scoped, singleton, scan

@singleton()
class Database:
    def __init__(self, url: str) -> None: ...

@scoped(key=UserRepository)
class PgUserRepository(UserRepository):
    def __init__(self, db: Database) -> None: ...

container = Container()
scan(container, "myapp.infrastructure")
container.register_instance(str, "postgresql+asyncpg://...")

async with container.scope() as scope:
    repo = await container.resolve(UserRepository, scope=scope)

Design rules

  • Annotation-driven_call_factory inspects get_type_hints() to resolve constructor parameters. No manual wiring for the common case.
  • Scope propagation — pass the active Scope into mediator.send() and it threads through all transient factory resolutions so that SCOPED dependencies (e.g. UnitOfWork) are reachable from handlers.
  • Cycle detection — circular dependencies raise ResolutionError at first resolution, not at registration time.
  • Overridecontainer.override(key, instance) replaces any registration; used in tests to swap real infrastructure for fakes.
  • No reflection at module-import time. scan() defers all class inspection to the first resolve() call.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qx_di-1.0.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qx_di-1.0.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file qx_di-1.0.0.tar.gz.

File metadata

  • Download URL: qx_di-1.0.0.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for qx_di-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ffda6a9a62394b9f24016b1d13620073a050e665ef919e359b66b326b77fd880
MD5 f5f1a836dc95b813b6f6ed960c2bada8
BLAKE2b-256 58b123555fa1b09ee1fc459ccc41fea247ea1a961386ddc795552d6bf013a2c9

See more details on using hashes here.

File details

Details for the file qx_di-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: qx_di-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for qx_di-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b839d19f560f3e4b43d171acae631c54d77f813b3b3eb04797305f642bada700
MD5 acb1c59540ba84f14e58f8d4d9e18346
BLAKE2b-256 95281e76b28d77c6d7c72ead3f5a417bffff572b149c710af4f25098cda911cc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page