Implement dependency injection system
- Enhanced existing src/server/utils/dependencies.py with optional SQLAlchemy import - Added comprehensive unit tests in tests/unit/test_dependencies.py - Created pytest configuration with asyncio support - Implemented SeriesApp singleton dependency with proper error handling - Added placeholders for database session and authentication dependencies - Updated infrastructure.md with dependency injection documentation - Completed dependency injection task from instructions.md Features implemented: - SeriesApp dependency with lazy initialization and singleton pattern - Configuration validation for anime directory - Comprehensive error handling for initialization failures - Common query parameters for pagination - Placeholder dependencies for future authentication and database features - 18 passing unit tests covering all dependency injection scenarios
This commit is contained in:
@@ -9,7 +9,11 @@ from typing import AsyncGenerator, Optional
|
||||
|
||||
from fastapi import Depends, HTTPException, status
|
||||
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
try:
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
except ImportError:
|
||||
AsyncSession = None
|
||||
|
||||
from src.config.settings import settings
|
||||
from src.core.SeriesApp import SeriesApp
|
||||
@@ -59,7 +63,7 @@ def reset_series_app() -> None:
|
||||
_series_app = None
|
||||
|
||||
|
||||
async def get_database_session() -> AsyncGenerator[AsyncSession, None]:
|
||||
async def get_database_session() -> AsyncGenerator[Optional[object], None]:
|
||||
"""
|
||||
Dependency to get database session.
|
||||
|
||||
@@ -144,7 +148,7 @@ class CommonQueryParams:
|
||||
|
||||
|
||||
def common_parameters(
|
||||
skip: int = 0,
|
||||
skip: int = 0,
|
||||
limit: int = 100
|
||||
) -> CommonQueryParams:
|
||||
"""
|
||||
@@ -177,4 +181,4 @@ async def log_request_dependency():
|
||||
|
||||
TODO: Implement request logging logic
|
||||
"""
|
||||
pass
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user