Files
FastapiAdmin/backend/app/core/di.py
T
zhangtao 53d2a9d13e chore: cleanup old frontend code and update project configs
This commit removes the deprecated frontend/web-old directory, updates various project configuration files including tsconfig, vite config, environment variables, and backend data models. It also fixes several API paths, adds tenant awareness to multiple models, and makes minor UI adjustments.
2026-05-27 01:12:03 +08:00

46 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""依赖注入容器
使用 dependency-injector 管理应用依赖,为后续 Repository 模式迁移提供基础。
当前状态:容器框架已搭建,但现有代码仍可直接使用 CRUDBase。
Phase 2 将逐步迁移 Service 层使用容器注入的 Repository。
用法:
from app.core.di import container
# 通过容器获取依赖
event_bus = container.event_bus()
"""
from dependency_injector import containers, providers
from app.config.setting import get_settings
class ApplicationContainer(containers.DeclarativeContainer):
"""全局依赖注入容器
管理应用的各层依赖:
- 配置
- 基础设施(Redis、数据库会话由 FastAPI Depends 管理)
- RepositoryPhase 2 实现)
- Domain ServicesPhase 3 实现)
"""
# ==================== 配置 ====================
config = providers.Singleton(get_settings)
# ==================== 基础设施(待后续 Phase 启用) ====================
# redis_client = providers.Singleton(RedisClient)
# cache_manager = providers.Singleton(CacheManager, redis=redis_client)
# event_bus = providers.Singleton(EventBus)
# task_queue = providers.Singleton(TaskQueue)
# ==================== RepositoryPhase 2 实现) ====================
# user_repository = providers.Factory(UserRepositoryImpl)
# role_repository = providers.Factory(RoleRepositoryImpl)
# 全局容器单例
container = ApplicationContainer()