feat: modern-di integration for Starlette#1
Merged
Conversation
Also bumps the starlette dependency cap from <1 to <2: the repo's dev group pins httpx2 (the package Starlette 1.x's TestClient imports), but the runtime dependency capped starlette below 1, which resolves to 0.52.1 and needs plain httpx instead. That combination made starlette.testclient unimportable and blocked every TestClient-based test added here. Flagging for confirmation since it's a version-range decision outside this task's stated file list. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… architecture/ Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…nnection identity Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the
modern-di-starletteintegration perplanning/changes/2026-07-02.01-di-integration.Starlette has no native DI (FastAPI's
Dependsis a FastAPI addition), so this uses the decorator path:setup_di(app, container)— attaches the root container toapp.state, registers connection providers, composes the app lifespan (reopen-on-startup so restarts don't raiseContainerClosedError), and installs a pure-ASGI middleware._DIMiddleware— builds a per-connection child container (Scope.REQUESTfor HTTP,Scope.SESSIONfor WebSocket), injects the connection as context, stashes it in the ASGI scope, and closes it infinally.FromDI+@inject— an inertAnnotatedmarker plus a decorator that resolves marked endpoint params from the request's child container. A clearRuntimeErrorfires if@injectis used withoutsetup_di.Public API:
FromDI,inject,setup_di,fetch_di_container,starlette_request_provider,starlette_websocket_provider. Structure mirrorsmodern-di-fastapi;architecture/truth home included.Tests: 8 passing, 100% line coverage (routes, websockets, lifespan incl. restart, middleware scoping, misuse error).
🤖 Generated with Claude Code