Skip to content

feat: aiogram-dialog DI support (modern_di_aiogram.dialog)#1

Merged
lesnik512 merged 3 commits into
mainfrom
feat/aiogram-dialog-inject
Jul 12, 2026
Merged

feat: aiogram-dialog DI support (modern_di_aiogram.dialog)#1
lesnik512 merged 3 commits into
mainfrom
feat/aiogram-dialog-inject

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Adds a modern_di_aiogram.dialog submodule with a dialog-aware @inject for aiogram-dialog getters and callbacks. Ships as 2.1.0 (minor, backward-compatible).

What

aiogram-dialog runs inside aiogram's dispatch, so setup_di's middleware already builds the per-update Scope.REQUEST child in data["modern_di_container"]. The new dialog.inject finds that child by call shape — getter → kwargs; callbacks carry a DialogManager positionally (args[-1] for 2-arg on_start/on_close, args[2] for 3–4-arg on_click/on_process_result) → manager.middleware_data[...] — and resolves FromDI.

  • Reuses the existing middleware, FromDI marker, and child-key from modern_di_aiogram.mainmain.py/__init__.py untouched (purely additive).
  • No new runtime dependency — the lookup is structural (duck-typed .middleware_data); aiogram-dialog>=2,<3 is a test dep only.
  • Import via from modern_di_aiogram.dialog import inject, FromDI.

Tests

tests/test_dialog.py drives a real two-dialog flow bot-less via aiogram_dialog.test_tools (BotClient/MockMessageManager), covering all four callback shapes (getter, on_start, on_click, on_process_result) + passthrough + per-update child close. 100% coverage; ruff/ty/eof clean.

Reviewed per-task + whole-branch on the most capable model; the dispatch was verified against the installed aiogram-dialog source.

🤖 Generated with Claude Code

lesnik512 and others added 3 commits July 12, 2026 09:41
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Final-review cleanups: remove an unused _TOKEN constant from the dialog test,
and document that a FromDI getter param must not collide with a middleware_data
key (getters are called as getter(**middleware_data)).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lesnik512 lesnik512 merged commit 05cb060 into main Jul 12, 2026
6 checks passed
@lesnik512 lesnik512 deleted the feat/aiogram-dialog-inject branch July 12, 2026 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant