mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-26 11:33:58 +03:00
Add overriding logic for Container provider
This commit is contained in:
parent
f95dadfc23
commit
b727be3f9a
File diff suppressed because it is too large
Load Diff
|
@ -2160,7 +2160,7 @@ cdef class Container(Provider):
|
||||||
deepcopy(self.container, memo),
|
deepcopy(self.container, memo),
|
||||||
**deepcopy(self.overriding_providers, memo),
|
**deepcopy(self.overriding_providers, memo),
|
||||||
)
|
)
|
||||||
# self._copy_overridings(copied, memo)
|
self._copy_overridings(copied, memo)
|
||||||
|
|
||||||
return copied
|
return copied
|
||||||
|
|
||||||
|
@ -2175,7 +2175,18 @@ cdef class Container(Provider):
|
||||||
|
|
||||||
def override(self, provider):
|
def override(self, provider):
|
||||||
"""Override provider with another provider."""
|
"""Override provider with another provider."""
|
||||||
raise Error('Provider {0} can not be overridden'.format(self))
|
self.container.override(provider)
|
||||||
|
return super(Container, self).override(provider)
|
||||||
|
|
||||||
|
def reset_last_overriding(self):
|
||||||
|
"""Reset last overriding provider."""
|
||||||
|
self.container.reset_last_overriding()
|
||||||
|
return super(Container, self).reset_last_overriding()
|
||||||
|
|
||||||
|
def reset_override(self):
|
||||||
|
"""Reset all overriding providers."""
|
||||||
|
self.container.reset_override()
|
||||||
|
return super(Container, self).reset_override()
|
||||||
|
|
||||||
cpdef object _provide(self, tuple args, dict kwargs):
|
cpdef object _provide(self, tuple args, dict kwargs):
|
||||||
"""Return single instance."""
|
"""Return single instance."""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user