aiteamutils 0.2.56__tar.gz → 0.2.58__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {aiteamutils-0.2.56 → aiteamutils-0.2.58}/PKG-INFO +1 -1
- {aiteamutils-0.2.56 → aiteamutils-0.2.58}/aiteamutils/__init__.py +5 -0
- {aiteamutils-0.2.56 → aiteamutils-0.2.58}/aiteamutils/dependencies.py +32 -1
- aiteamutils-0.2.58/aiteamutils/version.py +2 -0
- aiteamutils-0.2.56/aiteamutils/version.py +0 -2
- {aiteamutils-0.2.56 → aiteamutils-0.2.58}/.cursorrules +0 -0
- {aiteamutils-0.2.56 → aiteamutils-0.2.58}/.gitignore +0 -0
- {aiteamutils-0.2.56 → aiteamutils-0.2.58}/README.md +0 -0
- {aiteamutils-0.2.56 → aiteamutils-0.2.58}/aiteamutils/base_model.py +0 -0
- {aiteamutils-0.2.56 → aiteamutils-0.2.58}/aiteamutils/base_repository.py +0 -0
- {aiteamutils-0.2.56 → aiteamutils-0.2.58}/aiteamutils/base_service.py +0 -0
- {aiteamutils-0.2.56 → aiteamutils-0.2.58}/aiteamutils/cache.py +0 -0
- {aiteamutils-0.2.56 → aiteamutils-0.2.58}/aiteamutils/config.py +0 -0
- {aiteamutils-0.2.56 → aiteamutils-0.2.58}/aiteamutils/database.py +0 -0
- {aiteamutils-0.2.56 → aiteamutils-0.2.58}/aiteamutils/enums.py +0 -0
- {aiteamutils-0.2.56 → aiteamutils-0.2.58}/aiteamutils/exceptions.py +0 -0
- {aiteamutils-0.2.56 → aiteamutils-0.2.58}/aiteamutils/security.py +0 -0
- {aiteamutils-0.2.56 → aiteamutils-0.2.58}/aiteamutils/validators.py +0 -0
- {aiteamutils-0.2.56 → aiteamutils-0.2.58}/pyproject.toml +0 -0
- {aiteamutils-0.2.56 → aiteamutils-0.2.58}/setup.py +0 -0
@@ -21,6 +21,7 @@ from .base_repository import BaseRepository
|
|
21
21
|
from .validators import validate_with
|
22
22
|
from .enums import ActivityType
|
23
23
|
from .version import __version__
|
24
|
+
from .dependencies import setup_dependencies, register_service
|
24
25
|
|
25
26
|
__all__ = [
|
26
27
|
# Base Models
|
@@ -31,6 +32,10 @@ __all__ = [
|
|
31
32
|
# Database
|
32
33
|
"DatabaseService",
|
33
34
|
|
35
|
+
# Dependencies
|
36
|
+
"setup_dependencies",
|
37
|
+
"register_service",
|
38
|
+
|
34
39
|
# Exceptions
|
35
40
|
"CustomException",
|
36
41
|
"ErrorCode",
|
@@ -15,6 +15,23 @@ T = TypeVar("T", bound=BaseService)
|
|
15
15
|
R = TypeVar("R", bound=BaseRepository)
|
16
16
|
|
17
17
|
_service_registry: Dict[str, Dict[str, Any]] = {}
|
18
|
+
_session_provider = None
|
19
|
+
|
20
|
+
__all__ = [
|
21
|
+
"setup_dependencies",
|
22
|
+
"register_service",
|
23
|
+
"get_service",
|
24
|
+
"get_current_user"
|
25
|
+
]
|
26
|
+
|
27
|
+
def setup_dependencies(session_provider: Callable[[], AsyncGenerator[AsyncSession, None]]) -> None:
|
28
|
+
"""의존성 설정을 초기화합니다.
|
29
|
+
|
30
|
+
Args:
|
31
|
+
session_provider: 데이터베이스 세션을 제공하는 함수
|
32
|
+
"""
|
33
|
+
global _session_provider
|
34
|
+
_session_provider = session_provider
|
18
35
|
|
19
36
|
def register_service(
|
20
37
|
service_class: Type[T],
|
@@ -28,6 +45,13 @@ def register_service(
|
|
28
45
|
repository_class: 저장소 클래스 (선택)
|
29
46
|
**kwargs: 추가 의존성
|
30
47
|
"""
|
48
|
+
if _session_provider is None:
|
49
|
+
raise CustomException(
|
50
|
+
ErrorCode.INTERNAL_ERROR,
|
51
|
+
detail="Dependencies not initialized",
|
52
|
+
source_function="dependencies.register_service"
|
53
|
+
)
|
54
|
+
|
31
55
|
service_name = service_class.__name__
|
32
56
|
_service_registry[service_name] = {
|
33
57
|
"service_class": service_class,
|
@@ -103,9 +127,16 @@ def get_service(service_name: str) -> Callable:
|
|
103
127
|
Returns:
|
104
128
|
Callable: 서비스 의존성 함수
|
105
129
|
"""
|
130
|
+
if _session_provider is None:
|
131
|
+
raise CustomException(
|
132
|
+
ErrorCode.INTERNAL_ERROR,
|
133
|
+
detail="Dependencies not initialized",
|
134
|
+
source_function="dependencies.get_service"
|
135
|
+
)
|
136
|
+
|
106
137
|
async def _get_service_dependency(
|
107
138
|
request: Request,
|
108
|
-
session: AsyncSession
|
139
|
+
session: AsyncSession = Depends(_session_provider)
|
109
140
|
) -> BaseService:
|
110
141
|
return await _get_service(service_name, session, request)
|
111
142
|
return _get_service_dependency
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|