Implemented CLEAN architecture with clear separation of concerns: - Domain layer with entities (Player, Team, Stats, FantasyTeam) and repository interfaces - Application layer with use case implementations - Infrastructure layer with NHL API and Yahoo Fantasy API adapters - Presentation layer with FastAPI configuration and dependency injection Key features: - Swappable data source adapters (NHL API, Yahoo Fantasy API) - Repository pattern for data access abstraction - Dependency injection for loose coupling - FastAPI framework with async support - PostgreSQL database configuration - Environment-based configuration management Technology stack: Python 3.11+, FastAPI, PostgreSQL, nhl-api-py, yfpy 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
"""FastAPI dependency injection configuration."""
|
|
from functools import lru_cache
|
|
|
|
from src.domain.repositories import PlayerRepository, TeamRepository, FantasyRepository
|
|
from src.infrastructure.adapters.nhl import NHLPlayerAdapter, NHLTeamAdapter
|
|
from src.infrastructure.adapters.yahoo_fantasy import YahooFantasyAdapter
|
|
from src.infrastructure.config import Settings, get_settings
|
|
|
|
|
|
@lru_cache()
|
|
def get_cached_settings() -> Settings:
|
|
"""Returns cached application settings."""
|
|
return get_settings()
|
|
|
|
|
|
def get_player_repository() -> PlayerRepository:
|
|
"""
|
|
Provides the PlayerRepository implementation.
|
|
|
|
This function can be modified to return different implementations
|
|
without changing any business logic or API code.
|
|
"""
|
|
return NHLPlayerAdapter()
|
|
|
|
|
|
def get_team_repository() -> TeamRepository:
|
|
"""
|
|
Provides the TeamRepository implementation.
|
|
|
|
This function can be modified to return different implementations
|
|
without changing any business logic or API code.
|
|
"""
|
|
return NHLTeamAdapter()
|
|
|
|
|
|
def get_fantasy_repository() -> FantasyRepository:
|
|
"""
|
|
Provides the FantasyRepository implementation.
|
|
|
|
This function can be modified to return different implementations
|
|
without changing any business logic or API code.
|
|
"""
|
|
settings = get_cached_settings()
|
|
return YahooFantasyAdapter(
|
|
consumer_key=settings.yahoo_consumer_key,
|
|
consumer_secret=settings.yahoo_consumer_secret,
|
|
)
|