Skip to content

Commit bba3be8

Browse files
authored
feat: 📝 Update documentation
1 parent 5c770cd commit bba3be8

3 files changed

Lines changed: 9 additions & 10 deletions

File tree

documentation/integrations.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ _For a better understanding of the scopes, [here's the associated documentation]
4545
Here's how to configure FastAPI:
4646

4747
```python
48-
from collections.abc import AsyncIterator, Awaitable, Callable
48+
from collections.abc import AsyncIterator
4949
from contextlib import asynccontextmanager
5050
from enum import StrEnum, auto
5151

52-
from fastapi import FastAPI, Request, Response
52+
from fastapi import Depends, FastAPI, Request
5353
from injection import adefine_scope, reserve_scoped_slot
5454

5555
class InjectionScope(StrEnum):
@@ -61,16 +61,15 @@ async def lifespan(_: FastAPI) -> AsyncIterator[None]:
6161
async with adefine_scope(InjectionScope.LIFESPAN, kind="shared"):
6262
yield
6363

64-
app = FastAPI(lifespan=lifespan)
65-
6664
request_slot_key = reserve_scoped_slot(Request, InjectionScope.REQUEST)
6765

68-
@app.middleware("http")
69-
async def define_request_scope_middleware(
70-
request: Request,
71-
handler: Callable[[Request], Awaitable[Response]],
72-
) -> Response:
66+
async def request_scope(request: Request) -> AsyncIterator[None]:
7367
async with adefine_scope(InjectionScope.REQUEST) as scope:
7468
scope.set_slot(request_slot_key, request)
75-
return await handler(request)
69+
yield
70+
71+
app = FastAPI(
72+
dependencies=[Depends(request_scope)],
73+
lifespan=lifespan,
74+
)
7675
```

0 commit comments

Comments
 (0)