Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions planning/releases/2.0.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# modern-di-starlette 2.0.0 — first release

The initial release of `modern-di-starlette`, the [modern-di](https://modern-di.modern-python.org) integration for [Starlette](https://www.starlette.io). 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](https://modern-di.modern-python.org/integrations/starlette/).

## 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.