"""Shared FastAPI dependencies — the composition root for request-scoped wiring. Concrete adapters are bound to ports here so routers and services stay decoupled from infrastructure. Repository/service providers are added in later steps as the domain grows. """ from collections.abc import AsyncIterator from typing import Annotated from fastapi import Depends from sqlalchemy.ext.asyncio import AsyncSession from app.infrastructure.db import get_sessionmaker async def get_session() -> AsyncIterator[AsyncSession]: """Request-scoped DB session. Commits on success, rolls back on exception.""" session = get_sessionmaker()() try: yield session await session.commit() except Exception: await session.rollback() raise finally: await session.close() SessionDep = Annotated[AsyncSession, Depends(get_session)]