Releases: modern-python/modern-di-starlette
Releases · modern-python/modern-di-starlette
Release list
2.0.0
modern-di-starlette 2.0.0 — first release
The initial release of modern-di-starlette, the modern-di integration for Starlette. It wires a modern-di container into a Starlette app and resolves dependencies into endpoints. The version starts at 2.0.0 to track the modern-di 2.x ecosystem alongside the other official integrations.
Starlette has no dependency-injection system of its own, so this integration follows modern-di's decorator path: a pure-ASGI middleware owns the per-connection container lifecycle, and an @inject decorator with FromDI markers resolves dependencies (there is no Depends).
Feature
setup_di(app, container). Attaches the root container toapp.state, registers the connection providers, composes the app lifespan (the root container reopens on each startup, so repeated lifespan cycles work), and installs the DI middleware. Returns the container.- Per-connection child containers. A pure-ASGI middleware opens a
Scope.REQUESTchild container for each HTTP request and aScope.SESSIONchild for each WebSocket connection, injects the connection as context, and closes it when the connection ends. FromDI+@inject. Mark an endpoint parameter withAnnotated[T, FromDI(provider_or_type)]and decorate the endpoint with@inject; the decorator resolves each marked parameter from the request's child container. A clearRuntimeErroris raised if@injectruns withoutsetup_di.fetch_di_container(app)and thestarlette_request_provider/starlette_websocket_providercontext providers round out the public API.
Packaging
- Requires
starlette>=0.40,<2andmodern-di>=2.21.0,<3; Python 3.10–3.14. - Ships
py.typed; zero runtime dependencies beyond Starlette and modern-di.
Downstream
No action needed — this is a new package. See the Starlette integration docs.
Internals
- 100% line coverage;
ruff,ty, andeof-fixerclean across Python 3.10–3.14. - Uses the portable planning convention (
planning/) with anarchitecture/truth home; releases are tag-driven.