diff --git a/backend/app/dependencies.py b/backend/app/dependencies.py index d037258..6334c1f 100644 --- a/backend/app/dependencies.py +++ b/backend/app/dependencies.py @@ -9,7 +9,7 @@ directly — to keep coupling explicit and testable. import datetime from collections.abc import AsyncGenerator from dataclasses import dataclass -from typing import Annotated, Protocol, cast +from typing import Annotated, cast import aiohttp import aiosqlite @@ -33,27 +33,12 @@ from app.repositories.protocols import ( ) from app.services.geo_cache import GeoCache from app.utils.constants import SESSION_COOKIE_NAME -from app.utils.runtime_state import RuntimeState +from app.utils.runtime_state import ApplicationState, RuntimeState from app.utils.session_cache import NoOpSessionCache, SessionCache log: structlog.stdlib.BoundLogger = structlog.get_logger() -class AppState(Protocol): - """Partial view of the FastAPI application state used by dependencies.""" - - settings: Settings - http_session: aiohttp.ClientSession - scheduler: AsyncIOScheduler - server_status: ServerStatus - pending_recovery: PendingRecovery | None - last_activation: dict[str, datetime.datetime] | None - runtime_settings: Settings | None - runtime_state: RuntimeState - session_cache: SessionCache - geo_cache: GeoCache # noqa: F821 - - @dataclass class ApplicationContext: """A typed wrapper around shared application lifecycle resources.""" @@ -87,7 +72,7 @@ def _session_cache_enabled(settings: Settings) -> bool: def _build_app_context(request: Request) -> ApplicationContext: - state = cast("AppState", request.app.state) + state = cast(ApplicationState, request.app.state) session_cache = getattr(state, "session_cache", None) if session_cache is None: session_cache = NoOpSessionCache()