1717 uuid4 ,
1818)
1919
20- from dependency_injector .wiring import (
21- Provide ,
22- inject ,
23- )
24-
2520from minos .common import (
2621 NULL_DATETIME ,
2722 NULL_UUID ,
2823 DeclarativeModel ,
24+ Inject ,
2925 NotProvidedException ,
3026)
3127
@@ -69,61 +65,65 @@ def __init__(self, uuid: UUID, *args, **kwargs):
6965 super ().__init__ (uuid = uuid , * args , ** kwargs )
7066
7167
68+ T = TypeVar ("T" , bound = "RootEntity" )
69+
70+
7271class RootEntity (Entity ):
7372 """Base Root Entity class."""
7473
7574 version : int
7675 created_at : datetime
7776 updated_at : datetime
7877
79- @inject
78+ _event_repository : EventRepository
79+ _snapshot_repository : SnapshotRepository
80+
81+ @Inject ()
8082 def __init__ (
8183 self ,
8284 * args ,
8385 uuid : UUID = NULL_UUID ,
8486 version : int = 0 ,
8587 created_at : datetime = NULL_DATETIME ,
8688 updated_at : datetime = NULL_DATETIME ,
87- _event_repository : EventRepository = Provide [ "event_repository" ] ,
88- _snapshot_repository : SnapshotRepository = Provide [ "snapshot_repository" ] ,
89+ _event_repository : EventRepository ,
90+ _snapshot_repository : SnapshotRepository ,
8991 ** kwargs ,
9092 ):
9193
9294 super ().__init__ (version , created_at , updated_at , * args , uuid = uuid , ** kwargs )
9395
94- if _event_repository is None or isinstance ( _event_repository , Provide ) :
96+ if _event_repository is None :
9597 raise NotProvidedException (f"A { EventRepository !r} instance is required." )
96- if _snapshot_repository is None or isinstance ( _snapshot_repository , Provide ) :
98+ if _snapshot_repository is None :
9799 raise NotProvidedException (f"A { SnapshotRepository !r} instance is required." )
98100
99101 self ._event_repository = _event_repository
100102 self ._snapshot_repository = _snapshot_repository
101103
102104 @classmethod
103- @inject
104- async def get (
105- cls : Type [T ], uuid : UUID , * , _snapshot_repository : SnapshotRepository = Provide ["snapshot_repository" ], ** kwargs
106- ) -> T :
105+ @Inject ()
106+ async def get (cls : Type [T ], uuid : UUID , * , _snapshot_repository : SnapshotRepository , ** kwargs ) -> T :
107107 """Get one instance from the database based on its identifier.
108108
109109 :param uuid: The identifier of the instance.
110110 :param _snapshot_repository: Snapshot to be set to the root entity.
111111 :return: A ``RootEntity`` instance.
112112 """
113- if _snapshot_repository is None or isinstance ( _snapshot_repository , Provide ) :
113+ if _snapshot_repository is None :
114114 raise NotProvidedException (f"A { SnapshotRepository !r} instance is required." )
115115
116116 # noinspection PyTypeChecker
117117 return await _snapshot_repository .get (cls .classname , uuid , _snapshot_repository = _snapshot_repository , ** kwargs )
118118
119119 @classmethod
120- @inject
120+ @Inject ()
121121 def get_all (
122122 cls : Type [T ],
123123 ordering : Optional [_Ordering ] = None ,
124124 limit : Optional [int ] = None ,
125125 * ,
126- _snapshot_repository : SnapshotRepository = Provide [ "snapshot_repository" ] ,
126+ _snapshot_repository : SnapshotRepository ,
127127 ** kwargs ,
128128 ) -> AsyncIterator [T ]:
129129 """Get all instance from the database.
@@ -135,7 +135,7 @@ def get_all(
135135 :param _snapshot_repository: Snapshot to be set to the root entity.
136136 :return: A ``RootEntity`` instance.
137137 """
138- if _snapshot_repository is None or isinstance ( _snapshot_repository , Provide ) :
138+ if _snapshot_repository is None :
139139 raise NotProvidedException (f"A { SnapshotRepository !r} instance is required." )
140140
141141 # noinspection PyTypeChecker
@@ -144,14 +144,14 @@ def get_all(
144144 )
145145
146146 @classmethod
147- @inject
147+ @Inject ()
148148 def find (
149149 cls : Type [T ],
150150 condition : _Condition ,
151151 ordering : Optional [_Ordering ] = None ,
152152 limit : Optional [int ] = None ,
153153 * ,
154- _snapshot_repository : SnapshotRepository = Provide [ "snapshot_repository" ] ,
154+ _snapshot_repository : SnapshotRepository ,
155155 ** kwargs ,
156156 ) -> AsyncIterator [T ]:
157157 """Find a collection of instances based on a given ``Condition``.
@@ -164,7 +164,7 @@ def find(
164164 :param _snapshot_repository: Snapshot to be set to the instances.
165165 :return: An asynchronous iterator of ``RootEntity`` instances.
166166 """
167- if _snapshot_repository is None or isinstance ( _snapshot_repository , Provide ) :
167+ if _snapshot_repository is None :
168168 raise NotProvidedException (f"A { SnapshotRepository !r} instance is required." )
169169 # noinspection PyTypeChecker
170170 return _snapshot_repository .find (
@@ -352,6 +352,3 @@ def from_diff(cls: Type[T], event: Event, *args, **kwargs) -> T:
352352 ** event .get_fields (),
353353 ** kwargs ,
354354 )
355-
356-
357- T = TypeVar ("T" , bound = RootEntity )
0 commit comments