From 03f95f340a1e891f03f72ad38fdbca878afff96d Mon Sep 17 00:00:00 2001 From: Artur Shiriev Date: Fri, 26 Jun 2026 12:40:10 +0300 Subject: [PATCH] refactor: single-source connection->scope mapping in build_di_container --- modern_di_fastapi/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modern_di_fastapi/main.py b/modern_di_fastapi/main.py index c1415c9..7f93f0b 100644 --- a/modern_di_fastapi/main.py +++ b/modern_di_fastapi/main.py @@ -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