Skip to content

Adopt the modern-di integration kit#31

Merged
lesnik512 merged 6 commits into
mainfrom
integration-kit-conversion
Jul 13, 2026
Merged

Adopt the modern-di integration kit#31
lesnik512 merged 6 commits into
mainfrom
integration-kit-conversion

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Summary

modern-di 2.28.0 shipped modern_di.integrations — framework-agnostic primitives that formalize what this package's _DiMiddleware.consume_scope and Dependency/FromDI already hand-roll. This swaps the hand-rolled internals for kit calls. No public-API change; zero test-file changes.

Sixth of 13 planned adapter conversions (after starlette 2.2.0, fastapi 2.10.0, litestar 2.13.0, aiohttp 2.2.0, flask 2.1.0). FastStream combines traits from two prior conversions: like Flask, it has exactly one connection/message type (faststream.StreamMessage, broker-agnostic) so integrations.bind() is used directly with no classify_connection; unlike Flask, consume_scope wraps a single call site, so a Container async-context-manager block IS introduced. Like fastapi/litestar, FastStream has its own native DI seam (Depends), so there's no hand-rolled @inject to replace.

  • consume_scope now derives scope/context via integrations.bind(faststream_message_provider, msg) and opens the child container via async with ... as request_container:, nested with the existing sync with self.context.scope(...): block. The dead import modern_di (bare module) is removed.
  • Dependency's field renamed to marker: integrations.Marker[T_co]; __call__ delegates to self.marker.resolve(request_container). FromDI constructs Dependency(integrations.Marker(dependency)).
  • architecture/dependency-injection.md promoted to describe the new internals.
  • Bumps the modern-di floor to >=2.28,<3.

Test plan

  • just test-ci — 100% line coverage, all 5 tests passing, zero test-file changes
  • just lint-ci — ruff, ty, check-planning all clean
  • Per-task spec + quality review (5 tasks, all approved)
  • Whole-branch review (approved, no findings — including a traced verification that the new nested async-with/with structure preserves the original try/finally's exception-ordering)

@lesnik512
lesnik512 merged commit cf44077 into main Jul 13, 2026
6 checks passed
@lesnik512
lesnik512 deleted the integration-kit-conversion branch July 13, 2026 16:55
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