mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-05-22 21:46:17 +03:00
46 lines
954 B
Python
46 lines
954 B
Python
from dependency_injector import containers, providers
|
|
|
|
|
|
def get_value(value):
|
|
return value
|
|
|
|
|
|
class Core(containers.DeclarativeContainer):
|
|
|
|
config = providers.Configuration('core')
|
|
|
|
value_getter = providers.Callable(get_value, config.value)
|
|
|
|
|
|
class Services(containers.DeclarativeContainer):
|
|
|
|
config = providers.Configuration('services')
|
|
|
|
value_getter = providers.Callable(get_value, config.value)
|
|
|
|
|
|
root_config = providers.Configuration('main')
|
|
core = Core(config=root_config.core)
|
|
services = Services(config=root_config.services)
|
|
|
|
root_config.override(
|
|
{
|
|
'core': {
|
|
'value': 'core',
|
|
},
|
|
'services': {
|
|
'value': 'services',
|
|
},
|
|
},
|
|
)
|
|
|
|
print(core.value_getter())
|
|
print(services.value_getter())
|
|
|
|
print(core.config(), core.config.value())
|
|
print(services.config(), services.config.value())
|
|
|
|
print(root_config.children)
|
|
print(core.config.children)
|
|
print(services.config.children)
|