File tree Expand file tree Collapse file tree 2 files changed +22
-10
lines changed Expand file tree Collapse file tree 2 files changed +22
-10
lines changed Original file line number Diff line number Diff line change @@ -322,9 +322,6 @@ def wire( # noqa: C901
322322 packages : Optional [Iterable [ModuleType ]] = None ,
323323) -> None :
324324 """Wire container providers with provided packages and modules."""
325- if not _is_declarative_container_instance (container ):
326- raise Exception ('Can wire only an instance of the declarative container' )
327-
328325 if not modules :
329326 modules = []
330327
@@ -655,12 +652,6 @@ def _is_patched(fn):
655652 return getattr (fn , '__wired__' , False ) is True
656653
657654
658- def _is_declarative_container_instance (instance : Any ) -> bool :
659- return (not isinstance (instance , type )
660- and getattr (instance , '__IS_CONTAINER__' , False ) is True
661- and getattr (instance , 'declarative_parent' , None ) is not None )
662-
663-
664655def _is_declarative_container (instance : Any ) -> bool :
665656 return (isinstance (instance , type )
666657 and getattr (instance , '__IS_CONTAINER__' , False ) is True
Original file line number Diff line number Diff line change 77 Provider ,
88 Closing ,
99)
10- from dependency_injector import errors
10+ from dependency_injector import containers , providers , errors
1111
1212# Runtime import to avoid syntax errors in samples on Python < 3.5
1313import os
@@ -335,6 +335,27 @@ def test_closing_resource_bypass_marker_injection(self):
335335 self .assertIsNot (result_1 , result_2 )
336336
337337
338+ class WireDynamicContainerTest (unittest .TestCase ):
339+
340+ def test_wire (self ):
341+ sub = containers .DynamicContainer ()
342+ sub .int_object = providers .Object (1 )
343+
344+ container = containers .DynamicContainer ()
345+ container .config = providers .Configuration ()
346+ container .service = providers .Factory (Service )
347+ container .sub = sub
348+
349+ container .wire (
350+ modules = [module ],
351+ packages = [package ],
352+ )
353+ self .addCleanup (container .unwire )
354+
355+ service = module .test_function ()
356+ self .assertIsInstance (service , Service )
357+
358+
338359class WiringAsyncInjectionsTest (AsyncTestCase ):
339360
340361 def test_async_injections (self ):
You can’t perform that action at this time.
0 commit comments