@@ -149,6 +149,31 @@ def __init__(self, transportations: List[AnyTagged[Car, Truck]]):
149149 any (isinstance (t , Banana ) for t in resolved_dependency .transportations )
150150 )
151151
152+ def test_resolve_injects_any_tagged_dependencies_when_single_tag (self ):
153+ class PrimaryPort :
154+ pass
155+
156+ class Http :
157+ pass
158+
159+ class Cli :
160+ pass
161+
162+ class App :
163+ def __init__ (self , ports : List [AnyTagged [PrimaryPort ]]):
164+ self .ports = ports
165+
166+ dependency_container = DependencyContainer .get_instance ()
167+ dependency_container .register_transient (Http , tags = {PrimaryPort })
168+ dependency_container .register_transient (Cli , tags = {PrimaryPort })
169+ dependency_container .register_transient (App )
170+
171+ app = dependency_container .resolve (App )
172+
173+ self .assertEqual (len (app .ports ), 2 )
174+ self .assertTrue (any (isinstance (p , Http ) for p in app .ports ))
175+ self .assertTrue (any (isinstance (p , Cli ) for p in app .ports ))
176+
152177 def test_resolve_injects_all_tagged_dependencies (self ):
153178 # arrange
154179 class Red :
@@ -189,6 +214,31 @@ def __init__(self, white_colors: List[AllTagged[Red, Green, Blue]]):
189214 self .assertIsInstance (resolved_dependency .white_colors [0 ], White )
190215 self .assertNotIsInstance (resolved_dependency .white_colors [0 ], NonWhite )
191216
217+ def test_resolve_injects_all_tagged_dependencies_when_single_tag (self ):
218+ class PrimaryPort :
219+ pass
220+
221+ class Http :
222+ pass
223+
224+ class Cli :
225+ pass
226+
227+ class App :
228+ def __init__ (self , ports : List [AllTagged [PrimaryPort ]]):
229+ self .ports = ports
230+
231+ dependency_container = DependencyContainer .get_instance ()
232+ dependency_container .register_transient (Http , tags = {PrimaryPort })
233+ dependency_container .register_transient (Cli , tags = {PrimaryPort })
234+ dependency_container .register_transient (App )
235+
236+ app = dependency_container .resolve (App )
237+
238+ self .assertEqual (len (app .ports ), 2 )
239+ self .assertTrue (any (isinstance (p , Http ) for p in app .ports ))
240+ self .assertTrue (any (isinstance (p , Cli ) for p in app .ports ))
241+
192242 def test_resolve_injects_empty_list_if_no_tags_match (self ):
193243 # arrange
194244 class PrimaryPort :
0 commit comments