mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 09:36:48 +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.
|
||||
- Refactor ``Configuration`` provider.
|
||||
- Improve ``DependenciesContainer`` provider overriding logic.
|
||||
- Update "bundles" example miniapp.
|
||||
|
||||
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
|
||||
for a set of providers of a particular container.
|
||||
|
||||
|
||||
Example code:
|
||||
|
||||
.. code-block:: python
|
||||
|
@ -520,6 +519,29 @@ cdef class DependenciesContainer(Object):
|
|||
self._override_providers(container=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):
|
||||
"""Override providers with providers from provided container."""
|
||||
|
|
|
@ -341,6 +341,22 @@ class DependenciesContainerTests(unittest.TestCase):
|
|||
self.assertTrue(dependency.overridden)
|
||||
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):
|
||||
provider = providers.DependenciesContainer(
|
||||
self.container, dependency=providers.Dependency())
|
||||
|
|
Loading…
Reference in New Issue
Block a user