Skip to content

Commit

Permalink
Merge 96716d7 into 93fa377
Browse files Browse the repository at this point in the history
  • Loading branch information
rmk135 committed Feb 15, 2021
2 parents 93fa377 + 96716d7 commit e0c32a9
Show file tree
Hide file tree
Showing 7 changed files with 5,138 additions and 4,844 deletions.
6 changes: 6 additions & 0 deletions docs/main/changelog.rst
Expand Up @@ -7,6 +7,12 @@ that were made in every particular version.
From version 0.7.6 *Dependency Injector* framework strictly
follows `Semantic versioning`_

Development version
-------------------
- Add support of aliases for ``Configuration`` provider.
See issue: `#394 <https://github.com/ets-labs/python-dependency-injector/issues/394>`_.
Thanks to `@gtors <https://github.com/gtors>`_ for suggesting the feature.

4.22.1
------
- Pin ``sphinx`` version to hotfix docs build.
Expand Down
19 changes: 19 additions & 0 deletions docs/providers/configuration.rst
Expand Up @@ -306,6 +306,25 @@ configuration provider to strict mode.

Modifier ``.required()`` should be specified before type modifier ``.as_*()``.

Aliases
-------

You can use ``Configuration`` provider with a context manager to create aliases.

.. literalinclude:: ../../examples/providers/configuration/configuration_alias.py
:language: python
:lines: 3-
:emphasize-lines: 14,22

.. note::

Library ``environs`` is a 3rd party library. You need to install it
separately::

pip install environs

Documentation is available on GitHub: https://github.com/sloria/environs

Injecting invariants
--------------------

Expand Down
36 changes: 36 additions & 0 deletions examples/providers/configuration/configuration_alias.py
@@ -0,0 +1,36 @@
"""`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',
),
)

0 comments on commit e0c32a9

Please sign in to comment.