python-dependency-injector/examples/providers/configuration/configuration_alias.py
Roman Mogylatov 64d37efa37
Configuration provider aliases (#397)
* Add implementation, typing stubs, and tests

* Add docs and example

* Update changelog
2021-02-15 09:11:39 -05:00

37 lines
931 B
Python

"""`Configuration` provider alias example."""
from dependency_injector import containers, providers
from environs import Env
class Container(containers.DeclarativeContainer):
config = providers.Configuration()
if __name__ == '__main__':
env = Env()
container = Container()
with container.config.some_plugin_name as plugin:
plugin.some_interval_ms.override(
env.int(
'SOME_INTERVAL_MS',
default=30000,
),
)
with plugin.kafka as kafka:
kafka.bootstrap_servers.override(
env.list(
'KAFKA_BOOTSTRAP_SERVERS',
default=['kafka1', 'kafka2'],
),
)
kafka.security_protocol.override(
env.str(
'KAFKA_SECURITY_PROTOCOL',
default='SASL_SSL',
),
)