From 4cf930dc597b08103e1eb647ed72987097f89e23 Mon Sep 17 00:00:00 2001 From: Woody Date: Thu, 23 Apr 2026 13:27:30 +0800 Subject: [PATCH] feat(backend): add dependency injection and update main entry point Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- backend/app/core/dependencies.py | 24 ++++++++++++++++++++++++ backend/app/main.py | 4 +++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 backend/app/core/dependencies.py diff --git a/backend/app/core/dependencies.py b/backend/app/core/dependencies.py new file mode 100644 index 0000000..28b1a9f --- /dev/null +++ b/backend/app/core/dependencies.py @@ -0,0 +1,24 @@ +from __future__ import annotations + +from functools import lru_cache + +from app.core.config import Settings, get_settings + +@lru_cache() +def get_settings_cached() -> Settings: + return get_settings() + + +# Placeholder for future DI wiring. Tests patch classes directly, so we keep +# a minimal API here to avoid import-time side effects. +def get_llm_client(): + settings = get_settings_cached() + from app.services.llm_client import LLMClient + return LLMClient(settings) + + +def get_rag_service(): + # Import lazily to avoid circular imports in tests + from app.services.rag import RAGService + llm = get_llm_client() + return RAGService(llm_client=llm) diff --git a/backend/app/main.py b/backend/app/main.py index 44c8aac..5b1cd3f 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -2,12 +2,14 @@ from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from app.routers import ingest, query +from app.core.config import get_settings +settings = get_settings() app = FastAPI(title="RAG Video Q&A", version="1.0.0") app.add_middleware( CORSMiddleware, - allow_origins=["http://localhost:5173", "http://localhost:3000"], + allow_origins=settings.cors_origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"],