Add provider linking

This commit is contained in:
Roman Mogylatov 2020-06-22 21:42:24 -04:00
parent 3ee714795b
commit 99a2fcc396
4 changed files with 2286 additions and 1824 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -92,6 +92,7 @@ cdef class CoroutineDelegate(Delegate):
cdef class Configuration(Object): cdef class Configuration(Object):
cdef str __name cdef str __name
cdef dict __children cdef dict __children
cdef tuple __linked
# Factory providers # Factory providers

View File

@ -1029,6 +1029,7 @@ cdef class Configuration(Object):
self.__name = name self.__name = name
self.__children = self._create_children(default) self.__children = self._create_children(default)
self.__linked = tuple()
def __deepcopy__(self, memo): def __deepcopy__(self, memo):
"""Create and return full copy of provider.""" """Create and return full copy of provider."""
@ -1041,6 +1042,7 @@ cdef class Configuration(Object):
copied = self.__class__(self.__name) copied = self.__class__(self.__name)
copied.__provides = deepcopy(self.__provides, memo) copied.__provides = deepcopy(self.__provides, memo)
copied.__children = deepcopy(self.__children, memo) copied.__children = deepcopy(self.__children, memo)
copied.__linked = deepcopy(self.__linked, memo)
self._copy_overridings(copied, memo) self._copy_overridings(copied, memo)
@ -1093,11 +1095,17 @@ cdef class Configuration(Object):
""" """
overriding_context = super(Configuration, self).override(provider) overriding_context = super(Configuration, self).override(provider)
for linked in self.__linked:
linked.override(provider)
if isinstance(provider, Configuration):
provider.link_provider(self)
value = self.__call__() value = self.__call__()
if not isinstance(value, dict): if not isinstance(value, dict):
return return
for name in value: for name in value.keys():
child_provider = self.__children.get(name) child_provider = self.__children.get(name)
if child_provider is None: if child_provider is None:
continue continue
@ -1129,6 +1137,10 @@ cdef class Configuration(Object):
child.reset_override() child.reset_override()
super(Configuration, self).reset_override() super(Configuration, self).reset_override()
def link_provider(self, provider):
"""Configuration link two configuration providers."""
self.__linked += (<Configuration?>provider,)
def update(self, value): def update(self, value):
"""Set configuration options. """Set configuration options.