modern-di-faststream 2.10.0 — adopt the modern-di integration kit
Maintenance release. No public API change — FromDI, setup_di,
fetch_di_container, and faststream_message_provider keep their
signatures and behavior. Swaps this package's hand-rolled connection
dispatch and marker resolution for the shared primitives in
modern_di.integrations,
shipped in
modern-di 2.28.0.
Sixth of 13 planned adapter conversions across the modern-di ecosystem
(after
modern-di-starlette 2.2.0,
modern-di-fastapi 2.10.0,
modern-di-litestar 2.13.0,
modern-di-aiohttp 2.2.0,
and
modern-di-flask 2.1.0).
FastStream combines traits from two prior conversions: like Flask, it has
exactly one connection/message type, so integrations.bind() is used
directly with no classify_connection; unlike Flask, its DI middleware
wraps a single call site, so a Container async-context-manager block is
introduced.
Internal refactors
_DiMiddleware.consume_scopenow derives scope/context via
integrations.bind(faststream_message_provider, msg), and opens the
per-message child container viaasync with ... as request_container:—
replacing the manualtry/finally: await request_container.close_async().
The existingwith self.context.scope(_REQUEST_CONTAINER_KEY, request_container):block stays a separate, nested plainwith
(ContextRepo.scopeis not an async context manager, so it can't combine
into oneasync with A, B:statement).Dependency's field is renamed from a rawdependencyto
marker: integrations.Marker[T_co];__call__becomes
self.marker.resolve(request_container).FromDInow constructs
Dependency(integrations.Marker(dependency))— its own signature
(dependency, *, use_cache, cast) is unchanged.- Like
modern-di-fastapi/modern-di-litestar, this package is a
native-DI adapter (FastStream's ownDependsdrives resolution): no
hand-rolled@injectdecorator, noparse_markers/resolve_markers
usage. - The root container's callback-based lifecycle
(app.on_startup(container.open)/app.after_shutdown(container.close_async))
and the_DIMiddlewareFactory/_DiMiddlewaretwo-class split are
untouched by this change.
Packaging
- Bumps the
modern-difloor to>=2.28,<3.
Downstream
No action needed — the public API (FromDI, setup_di,
fetch_di_container, faststream_message_provider) is unchanged.
Upgrading only requires modern-di>=2.28.0.
Internals
- 100% line coverage;
ruff,tyclean across Python 3.10–3.14. - Built via
subagent-driven-development: 5 planned tasks, each with an
independent spec+quality review; a whole-branch review before merge that
traced the new nested async-with/with structure's exception ordering
against the original try/finally.