refactor: Implement Singleton pattern for DatabaseManager

Refactor the database handling to use a Singleton pattern for `DatabaseManager`.

- A single, module-level instance `db_manager` is created in `core/database.py` to ensure one database connection is used throughout the application.
- `MediaRepository` and `MainController` are updated to use this shared instance instead of creating their own.
- This simplifies dependency injection and prevents potential issues with multiple database connections.
- Also, update `review.md` to reflect the progress.
This commit is contained in:
2025-10-14 08:55:45 +02:00
parent 96c2495a8b
commit c8d9029df7
4 changed files with 28 additions and 6 deletions

View File

@@ -3,7 +3,7 @@ from PySide6.QtCore import Slot
from PySide6.QtGui import QPixmap
from PySide6.QtWidgets import QPushButton
from core.database import DatabaseManager
from core.database import db_manager
from core.media import MediaRepository
from core.camera.camera_manager import CameraManager
from ui.widgets.color_list_widget import ColorListWidget
@@ -14,8 +14,8 @@ from ui.widgets.split_view_widget import SplitView, CameraPlaceholder, ViewWithO
class MainController:
def __init__(self, view):
self.view = view
self.db = DatabaseManager()
self.media_repo = MediaRepository(self.db)
self.db = db_manager
self.media_repo = MediaRepository()
self.camera_manager = CameraManager()
# --- UI Widgets ---