mirror of
https://github.com/furyhawk/agent_alpha.git
synced 2026-07-21 02:25:34 +00:00
- 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.
42 lines
1.2 KiB
Python
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()
|