File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed
documentation/integrations Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -25,10 +25,11 @@ Here's how to configure FastAPI:
2525``` python
2626from collections.abc import AsyncIterator
2727from contextlib import asynccontextmanager
28+ from dataclasses import dataclass
2829from enum import StrEnum, auto
2930
3031from fastapi import Depends, FastAPI, Request
31- from injection import adefine_scope, reserve_scoped_slot
32+ from injection import MappedScope, Scoped, adefine_scope
3233
3334class InjectionScope (StrEnum ):
3435 LIFESPAN = auto()
@@ -39,11 +40,14 @@ async def lifespan(_: FastAPI) -> AsyncIterator[None]:
3940 async with adefine_scope(InjectionScope.LIFESPAN , kind = " shared" ):
4041 yield
4142
42- request_slot_key = reserve_scoped_slot(Request, InjectionScope.REQUEST )
43+ @dataclass
44+ class FastAPIRequestBindings :
45+ request: Scoped[Request]
46+
47+ scope = MappedScope(InjectionScope.REQUEST )
4348
4449async def request_scope (request : Request) -> AsyncIterator[None ]:
45- async with adefine_scope(InjectionScope.REQUEST ) as scope:
46- scope.set_slot(request_slot_key, request)
50+ async with FastAPIRequestBindings(request).scope.adefine():
4751 yield
4852
4953app = FastAPI(
You can’t perform that action at this time.
0 commit comments