refactor(api): use Annotated-style dependency injection

This commit is contained in:
MingxuanGame
2025-10-03 05:41:31 +00:00
parent 37b4eadf79
commit 346c2557cf
45 changed files with 623 additions and 577 deletions

View File

@@ -1,6 +1,6 @@
from __future__ import annotations
from typing import cast
from typing import Annotated, cast
from app.config import (
AWSS3StorageSettings,
@@ -9,11 +9,13 @@ from app.config import (
StorageServiceType,
settings,
)
from app.storage import StorageService
from app.storage import StorageService as OriginStorageService
from app.storage.cloudflare_r2 import AWSS3StorageService, CloudflareR2StorageService
from app.storage.local import LocalStorageService
storage: StorageService | None = None
from fastapi import Depends
storage: OriginStorageService | None = None
def init_storage_service():
@@ -50,3 +52,6 @@ def get_storage_service():
if storage is None:
return init_storage_service()
return storage
StorageService = Annotated[OriginStorageService, Depends(get_storage_service)]