Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co

## Project Overview

`modern-di` is a **zero-dependency** Python dependency injection framework that wires up object graphs from type annotations, manages lifetimes via hierarchical scopes, and supports both sync and async finalizers. Framework integrations (FastAPI, FastStream, LiteStar, Typer) and the pytest integration (`modern-di-pytest`) live in **separate repositories** and are published as separate PyPI packages.
`modern-di` is a **zero-dependency** Python dependency injection framework that wires up object graphs from type annotations, manages lifetimes via hierarchical scopes, and supports both sync and async finalizers. Framework integrations (aiohttp, FastAPI, FastStream, LiteStar, Starlette, Typer) and the pytest integration (`modern-di-pytest`) live in **separate repositories** and are published as separate PyPI packages.

## Commands

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
- Scopes and context management
- Python 3.10+ support
- Fully typed and tested
- Integrations with `FastAPI`, `FastStream`, `LiteStar`, `Starlette` and `Typer`
- Integrations with `aiohttp`, `FastAPI`, `FastStream`, `LiteStar`, `Starlette` and `Typer`
- Pytest integration (`modern-di-pytest`) — turns any DI dependency into a pytest fixture

## Install
Expand Down
5 changes: 3 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Welcome to the `modern-di` documentation!
- Scopes and context management
- Python 3.10+ support
- Fully typed and tested
- Integrations with `FastAPI`, `FastStream`, `LiteStar`, `Starlette`, `Typer`, and `pytest`
- Integrations with `aiohttp`, `FastAPI`, `FastStream`, `LiteStar`, `Starlette`, `Typer`, and `pytest`

Reference templates:

Expand Down Expand Up @@ -42,7 +42,7 @@ For end-to-end patterns drawn from real services, see the [Recipes](recipes/sqla
poetry add modern-di
```

If you want a framework integration, install the matching adapter — e.g. `modern-di-fastapi`, `modern-di-litestar`, `modern-di-faststream`, `modern-di-starlette`, `modern-di-typer`. For pytest support, install `modern-di-pytest`.
If you want a framework integration, install the matching adapter — e.g. `modern-di-aiohttp`, `modern-di-fastapi`, `modern-di-litestar`, `modern-di-faststream`, `modern-di-starlette`, `modern-di-typer`. For pytest support, install `modern-di-pytest`.

## 2. Describe your dependencies

Expand Down Expand Up @@ -94,6 +94,7 @@ Pick **one** of the two mutually-exclusive options below.

Pick the integration you need:

- [aiohttp](integrations/aiohttp.md)
- [FastAPI](integrations/fastapi.md)
- [FastStream](integrations/faststream.md)
- [LiteStar](integrations/litestar.md)
Expand Down
11 changes: 11 additions & 0 deletions docs/integrations/writing-integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@ builds and closes the per-connection child, the decorator only reads it back fro
the ASGI scope and resolves. See [Frameworks without native
DI](#frameworks-without-native-di-the-decorator-path).

The **aiohttp** integration ([`modern-di-aiohttp`](aiohttp.md)) is another
middleware + decorator hybrid, for a non-ASGI server where the only connection
object at middleware entry is `web.Request` — a WebSocket is an upgraded HTTP
request, not a distinct type. It detects a WebSocket via
`web.WebSocketResponse().can_prepare(request).ok`, opens a `Scope.REQUEST`
child for an HTTP request or a `Scope.SESSION` child for a WebSocket, and —
because both connection providers bind `web.Request` — registers
`aiohttp_request_provider` by type while keeping `aiohttp_websocket_provider`
reference-only (`bound_type=None`). Its root lifecycle rides aiohttp's
`on_startup`/`on_cleanup` signals rather than a composed lifespan.

The **pytest** integration
([`modern-di-pytest`](pytest.md)) is a different shape: it has no app to wire, so
instead of `setup_di`/`FromDI` it exposes `modern_di_fixture` (turn one
Expand Down
4 changes: 2 additions & 2 deletions docs/introduction/comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Reach for a container when one of these is true:
the HTTP layer.

modern-di's core promise is exactly that: **one typed wiring shared across
FastAPI, Litestar, FastStream, Starlette, and Typer.**
aiohttp, FastAPI, Litestar, FastStream, Starlette, and Typer.**

## The landscape

Expand All @@ -34,7 +34,7 @@ FastAPI, Litestar, FastStream, Starlette, and Typer.**
| Scopes | APP→…→STEP (fixed chain) | RUNTIME→…→STEP (+ custom) | lifetimes (Singleton/Factory/Resource) | Singleton / Thread / None | request only |
| Resolution | sync (by design) | sync + async | sync + async | sync | async |
| First-party pytest plugin | ✅ | ✘ | ✘ | ✘ | n/a |
| Official integrations | 6 (FastAPI, Litestar, FastStream, Starlette, Typer, pytest) | ~20+ | FastAPI, Flask, … | Flask (1st-party), FastAPI (3rd-party) | n/a |
| Official integrations | 7 (aiohttp, FastAPI, Litestar, FastStream, Starlette, Typer, pytest) | ~20+ | FastAPI, Flask, … | Flask (1st-party), FastAPI (3rd-party) | n/a |
| Typed resolution | ✅ | ✅ | partial | ✅ | callable-keyed |
| License | MIT | Apache-2.0 | BSD-3 | BSD | — |
| Adoption | newest, very active | established, large community | most popular, mature | mature | built into FastAPI |
Expand Down