Skip to content

2.0.0

Choose a tag to compare

@github-actions github-actions released this 10 Jul 08:32
0123502

modern-di-aiogram 2.0.0 — first release

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

aiogram has no dependency-injection seam of its own (handlers receive values
from a middleware data dict), so this integration follows modern-di's
middleware + @inject decorator path: an update-level outer middleware owns
the per-update container lifecycle, and an @inject decorator (or
auto_inject=True) resolves FromDI markers.

Feature

  • setup_di(dispatcher, container, *, auto_inject=False). Stashes the root
    container on the dispatcher's workflow-data (read back with
    fetch_di_container(dispatcher)), registers the connection providers, wires
    the container's lifecycle to dispatcher.startup (reopen — so a restart
    works) and dispatcher.shutdown (close), and installs an update-level outer
    middleware. Returns the container.
  • Per-update child containers. The middleware builds one Scope.REQUEST
    child container per update, seeded with the aiogram Update and its concrete
    event (Message, CallbackQuery, …), stashes it in the handler data, and
    closes it when the update finishes — including on the handler error path.
  • FromDI + @inject. Mark a handler parameter with
    Annotated[T, FromDI(provider_or_type)] and decorate the handler with
    @inject; the decorator rewrites the handler signature (removing the DI
    params so aiogram doesn't try to fill them, adding the container by name) and
    resolves each marked parameter from the update's child container.
  • auto_inject=True. Wraps every handler registered before startup with
    @inject automatically, so individual handlers don't need the decorator.
  • aiogram_update_provider / aiogram_event_provider. Connection providers
    exposing the Update and the concrete TelegramObject event at
    Scope.REQUEST for injection into factories.

Packaging

  • Requires aiogram>=3.2,<4 and modern-di>=2.25,<3; Python 3.10–3.14. The
    >=3.2 floor is the earliest aiogram exposing HandlerObject.params, which
    auto_inject relies on.
  • Ships py.typed; zero runtime dependencies beyond aiogram and modern-di.
  • Resolution stays synchronous by design; only the per-update 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.