Skip to content

feat: modern-di integration for Starlette#1

Merged
lesnik512 merged 4 commits into
mainfrom
feat/di-integration
Jul 2, 2026
Merged

feat: modern-di integration for Starlette#1
lesnik512 merged 4 commits into
mainfrom
feat/di-integration

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Implements the modern-di-starlette integration per planning/changes/2026-07-02.01-di-integration.

Starlette has no native DI (FastAPI's Depends is a FastAPI addition), so this uses the decorator path:

  • setup_di(app, container) — attaches the root container to app.state, registers connection providers, composes the app lifespan (reopen-on-startup so restarts don't raise ContainerClosedError), and installs a pure-ASGI middleware.
  • _DIMiddleware — builds a per-connection child container (Scope.REQUEST for HTTP, Scope.SESSION for WebSocket), injects the connection as context, stashes it in the ASGI scope, and closes it in finally.
  • FromDI + @inject — an inert Annotated marker plus a decorator that resolves marked endpoint params from the request's child container. A clear RuntimeError fires if @inject is used without setup_di.

Public API: FromDI, inject, setup_di, fetch_di_container, starlette_request_provider, starlette_websocket_provider. Structure mirrors modern-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

lesnik512 and others added 4 commits July 2, 2026 10:23
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>
@lesnik512 lesnik512 merged commit a707312 into main Jul 2, 2026
6 checks passed
@lesnik512 lesnik512 deleted the feat/di-integration branch July 2, 2026 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant