mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-07-11 00:22:25 +03:00
Add provider linking
This commit is contained in:
parent
3ee714795b
commit
99a2fcc396
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -92,6 +92,7 @@ cdef class CoroutineDelegate(Delegate):
|
|||
cdef class Configuration(Object):
|
||||
cdef str __name
|
||||
cdef dict __children
|
||||
cdef tuple __linked
|
||||
|
||||
|
||||
# Factory providers
|
||||
|
|
|
@ -1029,6 +1029,7 @@ cdef class Configuration(Object):
|
|||
|
||||
self.__name = name
|
||||
self.__children = self._create_children(default)
|
||||
self.__linked = tuple()
|
||||
|
||||
def __deepcopy__(self, memo):
|
||||
"""Create and return full copy of provider."""
|
||||
|
@ -1041,6 +1042,7 @@ cdef class Configuration(Object):
|
|||
copied = self.__class__(self.__name)
|
||||
copied.__provides = deepcopy(self.__provides, memo)
|
||||
copied.__children = deepcopy(self.__children, memo)
|
||||
copied.__linked = deepcopy(self.__linked, memo)
|
||||
|
||||
self._copy_overridings(copied, memo)
|
||||
|
||||
|
@ -1093,11 +1095,17 @@ cdef class Configuration(Object):
|
|||
"""
|
||||
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__()
|
||||
if not isinstance(value, dict):
|
||||
return
|
||||
|
||||
for name in value:
|
||||
for name in value.keys():
|
||||
child_provider = self.__children.get(name)
|
||||
if child_provider is None:
|
||||
continue
|
||||
|
@ -1129,6 +1137,10 @@ cdef class Configuration(Object):
|
|||
child.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):
|
||||
"""Set configuration options.
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user