Skip to content
Merged
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
6 changes: 3 additions & 3 deletions modern_di_fastapi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ def setup_di(app: fastapi.FastAPI, container: Container) -> Container:

async def build_di_container(connection: HTTPConnection) -> typing.AsyncIterator[Container]:
context: dict[type[typing.Any], typing.Any] = {}
scope: Scope | None = None
scope = None
if isinstance(connection, fastapi.Request):
scope = Scope.REQUEST
scope = fastapi_request_provider.scope
context[fastapi.Request] = connection
elif isinstance(connection, fastapi.WebSocket):
context[fastapi.WebSocket] = connection
scope = Scope.SESSION
scope = fastapi_websocket_provider.scope
container = fetch_di_container(connection.app).build_child_container(context=context, scope=scope)
try:
yield container
Expand Down