Add overriding logic for Container provider

This commit is contained in:
Roman Mogylatov 2020-06-24 12:41:18 -04:00
parent f95dadfc23
commit b727be3f9a
2 changed files with 664 additions and 381 deletions

File diff suppressed because it is too large Load Diff

View File

@ -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."""