mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 01:26:51 +03:00
Add parsing of nested containers to declarative container
This commit is contained in:
parent
236fe316e3
commit
7bd0997f85
File diff suppressed because it is too large
Load Diff
|
@ -144,6 +144,12 @@ class DeclarativeContainerMetaClass(type):
|
|||
cdef tuple inherited_providers
|
||||
cdef type cls
|
||||
|
||||
containers = tuple((name, container)
|
||||
for name, container in six.iteritems(attributes)
|
||||
if is_container(container))
|
||||
|
||||
attributes['containers'] = dict(containers)
|
||||
|
||||
cls_providers = tuple((name, provider)
|
||||
for name, provider in six.iteritems(attributes)
|
||||
if isinstance(provider, Provider))
|
||||
|
@ -229,6 +235,12 @@ class DeclarativeContainer(object):
|
|||
:type: type
|
||||
"""
|
||||
|
||||
containers = dict()
|
||||
"""Read-only dictionary of all nested containers.
|
||||
|
||||
:type: dict[str, :py:class:`DeclarativeContainer`]
|
||||
"""
|
||||
|
||||
providers = dict()
|
||||
"""Read-only dictionary of all providers.
|
||||
|
||||
|
|
|
@ -250,3 +250,18 @@ class DeclarativeContainerTests(unittest.TestCase):
|
|||
|
||||
self.assertEqual(_Container1.p13(), 11)
|
||||
self.assertEqual(_Container2.p13(), 22)
|
||||
|
||||
def test_containers_attribute(self):
|
||||
class Container(containers.DeclarativeContainer):
|
||||
class Container1(containers.DeclarativeContainer):
|
||||
pass
|
||||
|
||||
class Container2(containers.DeclarativeContainer):
|
||||
pass
|
||||
|
||||
Container3 = containers.DynamicContainer()
|
||||
|
||||
self.assertEqual(Container.containers,
|
||||
dict(Container1=Container.Container1,
|
||||
Container2=Container.Container2,
|
||||
Container3=Container.Container3))
|
||||
|
|
Loading…
Reference in New Issue
Block a user