Skip to content

Releases: modern-python/modern-di-starlette

Release list

2.0.0

Choose a tag to compare

@github-actions github-actions released this 02 Jul 08:05
fd0563e

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 to app.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.REQUEST child container for each HTTP request and a Scope.SESSION child for each WebSocket connection, injects the connection as context, and closes it when the connection ends.
  • FromDI + @inject. Mark an endpoint parameter with Annotated[T, FromDI(provider_or_type)] and decorate the endpoint with @inject; the decorator resolves each marked parameter from the request's child container. A clear RuntimeError is raised if @inject runs without setup_di.
  • fetch_di_container(app) and the starlette_request_provider / starlette_websocket_provider context providers round out the public API.

Packaging

  • Requires starlette>=0.40,<2 and modern-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, 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.