Files
Mutual_Fund/config/deps.py
T

26 lines
592 B
Python
Raw Normal View History

2026-09-08 19:17:35 +08:00
"""FastAPI Depends 工厂:把池化会话按请求注入,用后即还。"""
from .database import milvus, mysql, neo4j, redis
async def get_db():
"""仓储/服务层用 AsyncSession(UoW):注入 BaseRepository。"""
async with mysql.get_session_factory()() as session:
yield session
async def get_mysql_conn():
async with mysql.get_session_factory()() as conn:
yield conn
def get_redis():
yield redis.client()
async def get_neo4j_session():
async with neo4j.get_session() as s:
yield s
def get_milvus():
yield milvus.client()