Files
agent_alpha/backend/core/dependencies.py
T
furyhawk 1c203b6bdb Refactor authentication and chat services to use Redis for token management and message storage
- Introduced `auth_token_repo` for handling auth token operations in Redis.
- Created `chat_repo` for managing chat sessions and messages in Redis.
- Implemented `ChatService` and `AuthService` to encapsulate business logic for chat and authentication.
- Updated routes to utilize new service and repository layers, removing direct database calls.
- Enhanced user management with `UserService` for CRUD operations and user authentication.
- Revised architecture documentation to reflect the new service-repository pattern.
2026-06-14 19:24:12 +08:00

42 lines
1.2 KiB
Python

"""FastAPI dependency injection providers."""
from __future__ import annotations
from typing import TYPE_CHECKING, AsyncIterator
from redis.asyncio import Redis
from sqlalchemy.ext.asyncio import AsyncSession
from backend.core.agent import AgentService
from backend.core.database import get_session as _get_db_session
from backend.core.database import get_valkey as _get_valkey
if TYPE_CHECKING:
from backend.core.config import Settings
async def get_settings() -> Settings:
"""Provide the application Settings singleton."""
from backend.core.config import Settings as _Settings
from backend.core.config import settings as _settings
return _settings
async def get_agent_service() -> AgentService:
"""Provide the lazily-initialised AgentService singleton."""
from backend.core.agent import get_service
return get_service()
async def get_db_session() -> AsyncIterator[AsyncSession]:
"""Provide an async SQLAlchemy session for route dependencies."""
async for session in _get_db_session():
yield session
async def get_valkey() -> Redis:
"""Provide the shared Valkey (Redis) async client."""
return await _get_valkey()