Skip to content

2.0.0

Latest

Choose a tag to compare

@github-actions github-actions released this 09 Jul 20:38
60db206

modern-di-taskiq 2.0.0 — first release

First release of the taskiq integration for modern-di. It wires a
modern-di container into a
taskiq broker and resolves dependencies into
task handlers, scoped per task. The version starts at 2.0.0 to track the
modern-di 2.x ecosystem alongside the other official integrations.

taskiq has its own dependency-injection system (TaskiqDepends), so this
integration follows modern-di's native-DI generator-dependency path:
FromDI returns a TaskiqDepends marker, and a generator dependency owns the
per-task container lifecycle.

Feature

  • setup_di(broker, container). Stashes the root container on the broker
    (broker.state, under a named constant, read back with
    fetch_di_container(broker)), registers the connection provider, and wires
    the container's lifecycle to the broker's worker events — reopening it on
    WORKER_STARTUP (so a worker restart works) and closing it on
    WORKER_SHUTDOWN. Returns the container.
  • Per-task child containers. A generator dependency opens one
    Scope.REQUEST child container per task, seeded with the current
    taskiq.TaskiqMessage as context, and closes it when the task finishes —
    including when the task raises. taskiq resolves the generator once per task,
    so every FromDI parameter in a task shares the same child.
  • FromDI. Mark a task parameter with
    Annotated[T, FromDI(provider_or_type)]; it resolves from the task's child
    container. FromDI accepts a provider reference or a bare type, dispatching
    through Container.resolve_dependency (so overrides, caching, and
    did-you-mean suggestions are inherited).
  • taskiq_message_provider. A ContextProvider binding
    taskiq.TaskiqMessage at Scope.REQUEST, so the current message is
    resolvable inside DI.

Packaging

  • Requires taskiq>=0.11,<0.13 and modern-di>=2.25,<3; Python 3.10–3.14.
  • Ships py.typed; zero runtime dependencies beyond taskiq and modern-di.
  • Resolution stays synchronous by design; only the per-task container builder
    and finalizers are async.

Downstream

No action needed — this is a new package.

Internals

  • 100% line coverage; ruff, ty, and eof-fixer clean across Python
    3.10–3.14.
  • Uses the portable planning convention (planning/) with an architecture/
    truth home; releases are tag-driven.