Skip to content

Commit 6c06548

Browse files
committed
Merge branch 'release/4.23.0' into master
2 parents 93fa377 + c28a4dc commit 6c06548

File tree

8 files changed

+5139
-4845
lines changed

8 files changed

+5139
-4845
lines changed

docs/main/changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ that were made in every particular version.
77
From version 0.7.6 *Dependency Injector* framework strictly
88
follows `Semantic versioning`_
99

10+
4.23.0
11+
------
12+
- Add support of aliases for ``Configuration`` provider.
13+
See issue: `#394 <https://github.com/ets-labs/python-dependency-injector/issues/394>`_.
14+
Thanks to `@gtors <https://github.com/gtors>`_ for suggesting the feature.
15+
1016
4.22.1
1117
------
1218
- Pin ``sphinx`` version to hotfix docs build.

docs/providers/configuration.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,25 @@ configuration provider to strict mode.
306306

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

309+
Aliases
310+
-------
311+
312+
You can use ``Configuration`` provider with a context manager to create aliases.
313+
314+
.. literalinclude:: ../../examples/providers/configuration/configuration_alias.py
315+
:language: python
316+
:lines: 3-
317+
:emphasize-lines: 14,22
318+
319+
.. note::
320+
321+
Library ``environs`` is a 3rd party library. You need to install it
322+
separately::
323+
324+
pip install environs
325+
326+
Documentation is available on GitHub: https://github.com/sloria/environs
327+
309328
Injecting invariants
310329
--------------------
311330

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""`Configuration` provider alias example."""
2+
3+
from dependency_injector import containers, providers
4+
from environs import Env
5+
6+
7+
class Container(containers.DeclarativeContainer):
8+
9+
config = providers.Configuration()
10+
11+
12+
if __name__ == '__main__':
13+
env = Env()
14+
container = Container()
15+
16+
with container.config.some_plugin_name as plugin:
17+
plugin.some_interval_ms.override(
18+
env.int(
19+
'SOME_INTERVAL_MS',
20+
default=30000,
21+
),
22+
)
23+
24+
with plugin.kafka as kafka:
25+
kafka.bootstrap_servers.override(
26+
env.list(
27+
'KAFKA_BOOTSTRAP_SERVERS',
28+
default=['kafka1', 'kafka2'],
29+
),
30+
)
31+
kafka.security_protocol.override(
32+
env.str(
33+
'KAFKA_SECURITY_PROTOCOL',
34+
default='SASL_SSL',
35+
),
36+
)

src/dependency_injector/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Top-level package."""
22

3-
__version__ = '4.22.1'
3+
__version__ = '4.23.0'
44
"""Version number.
55
66
:type: str

0 commit comments

Comments
 (0)