mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 17:47:02 +03:00
Merge branch 'improve-dependencies-container-overriding' into develop
This commit is contained in:
commit
96476ba9ca
|
@ -11,6 +11,7 @@ follows `Semantic versioning`_
|
||||||
------
|
------
|
||||||
- Improve ``Configuration`` provider overriding logic.
|
- Improve ``Configuration`` provider overriding logic.
|
||||||
- Refactor ``Configuration`` provider.
|
- Refactor ``Configuration`` provider.
|
||||||
|
- Improve ``DependenciesContainer`` provider overriding logic.
|
||||||
- Update "bundles" example miniapp.
|
- Update "bundles" example miniapp.
|
||||||
|
|
||||||
3.10.0
|
3.10.0
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -427,7 +427,6 @@ cdef class DependenciesContainer(Object):
|
||||||
Dependencies container provider is used to implement late static binding
|
Dependencies container provider is used to implement late static binding
|
||||||
for a set of providers of a particular container.
|
for a set of providers of a particular container.
|
||||||
|
|
||||||
|
|
||||||
Example code:
|
Example code:
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
@ -520,6 +519,29 @@ cdef class DependenciesContainer(Object):
|
||||||
self._override_providers(container=provider)
|
self._override_providers(container=provider)
|
||||||
return super(DependenciesContainer, self).override(provider)
|
return super(DependenciesContainer, self).override(provider)
|
||||||
|
|
||||||
|
def reset_last_overriding(self):
|
||||||
|
"""Reset last overriding provider.
|
||||||
|
|
||||||
|
:raise: :py:exc:`dependency_injector.errors.Error` if provider is not
|
||||||
|
overridden.
|
||||||
|
|
||||||
|
:rtype: None
|
||||||
|
"""
|
||||||
|
for child in self.__providers.values():
|
||||||
|
try:
|
||||||
|
child.reset_last_overriding()
|
||||||
|
except Error:
|
||||||
|
pass
|
||||||
|
super(DependenciesContainer, self).reset_last_overriding()
|
||||||
|
|
||||||
|
def reset_override(self):
|
||||||
|
"""Reset all overriding providers.
|
||||||
|
|
||||||
|
:rtype: None
|
||||||
|
"""
|
||||||
|
for child in self.__providers.values():
|
||||||
|
child.reset_override()
|
||||||
|
super(DependenciesContainer, self).reset_override()
|
||||||
|
|
||||||
cpdef object _override_providers(self, object container):
|
cpdef object _override_providers(self, object container):
|
||||||
"""Override providers with providers from provided container."""
|
"""Override providers with providers from provided container."""
|
||||||
|
|
|
@ -341,6 +341,22 @@ class DependenciesContainerTests(unittest.TestCase):
|
||||||
self.assertTrue(dependency.overridden)
|
self.assertTrue(dependency.overridden)
|
||||||
self.assertIs(dependency.last_overriding, self.container.dependency)
|
self.assertIs(dependency.last_overriding, self.container.dependency)
|
||||||
|
|
||||||
|
def test_reset_last_overriding(self):
|
||||||
|
dependency = self.provider.dependency
|
||||||
|
self.provider.override(self.container)
|
||||||
|
self.provider.reset_last_overriding()
|
||||||
|
|
||||||
|
self.assertIsNone(dependency.last_overriding)
|
||||||
|
self.assertIsNone(dependency.last_overriding)
|
||||||
|
|
||||||
|
def test_reset_override(self):
|
||||||
|
dependency = self.provider.dependency
|
||||||
|
self.provider.override(self.container)
|
||||||
|
self.provider.reset_override()
|
||||||
|
|
||||||
|
self.assertFalse(dependency.overridden)
|
||||||
|
self.assertFalse(dependency.overridden)
|
||||||
|
|
||||||
def test_init_with_container_and_providers(self):
|
def test_init_with_container_and_providers(self):
|
||||||
provider = providers.DependenciesContainer(
|
provider = providers.DependenciesContainer(
|
||||||
self.container, dependency=providers.Dependency())
|
self.container, dependency=providers.Dependency())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user