Skip to content

Commit 6a73b9d

Browse files
committed
Merge branch 'release/4.25.0' into master
2 parents c0d1e48 + a71154e commit 6a73b9d

File tree

12 files changed

+5962
-5657
lines changed

12 files changed

+5962
-5657
lines changed

docs/main/changelog.rst

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

10+
4.25.0
11+
------
12+
- Add ``application-multiple-containers-runtime-overriding`` example. This example demonstrates
13+
how to build application from multiple containers and override one container config from
14+
another one in the runtime.
15+
See issue: `#207 <https://github.com/ets-labs/python-dependency-injector/issues/207>`_.
16+
- Add attributes forwarding for the ``Dependency`` provider.
17+
1018
4.24.0
1119
------
1220
- Add docs on ``@containers.copy()`` decorator.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Application example (multiple containers, runtime config overriding)
2+
====================================================================
3+
4+
This example demonstrates how to build application from multiple containers
5+
and override one container config from another one in the runtime.
6+
7+
Run:
8+
9+
.. code-block:: bash
10+
11+
python -m example
12+
13+
You should see:
14+
15+
.. code-block:: bash
16+
17+
Adapter=[DB Path=[~/test]], queue=[Some storage]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Top-level package."""
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""Main module."""
2+
3+
from .containers import Application
4+
5+
6+
if __name__ == '__main__':
7+
application = Application()
8+
config = application.service.config()
9+
config.build()
10+
11+
print(application.repository.site())
12+
# Output: Adapter=[DB Path=[~/test]], queue=[Some storage]
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""Containers module."""
2+
3+
from dependency_injector import containers, providers
4+
5+
from .services import ConfigService
6+
7+
8+
class Core(containers.DeclarativeContainer):
9+
config = providers.Configuration('config')
10+
11+
12+
class Storage(containers.DeclarativeContainer):
13+
queue = providers.Singleton(lambda: 'Some storage')
14+
15+
16+
class Adapter(containers.DeclarativeContainer):
17+
core = providers.DependenciesContainer(config=providers.Configuration())
18+
tinydb = providers.Singleton(
19+
lambda db_path: f'DB Path=[{db_path}]',
20+
db_path=core.config.default.db_path,
21+
)
22+
23+
24+
class Repository(containers.DeclarativeContainer):
25+
adapter = providers.DependenciesContainer()
26+
storage = providers.DependenciesContainer()
27+
site = providers.Singleton(
28+
lambda adapter, queue: f'Adapter=[{adapter}], queue=[{queue}]',
29+
adapter=adapter.tinydb,
30+
queue=storage.queue,
31+
)
32+
33+
34+
class Service(containers.DeclarativeContainer):
35+
core = providers.DependenciesContainer()
36+
config = providers.Singleton(ConfigService, core.config.provider)
37+
38+
39+
class Application(containers.DeclarativeContainer):
40+
41+
core = providers.Container(Core)
42+
storage = providers.Container(Storage)
43+
adapter = providers.Container(Adapter, core=core)
44+
repository = providers.Container(Repository, adapter=adapter, storage=storage)
45+
service = providers.Container(Service, core=core)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""Services module."""
2+
3+
4+
class ConfigService:
5+
def __init__(self, config):
6+
self._config = config
7+
8+
def build(self):
9+
self._config.from_dict({'default': {'db_path': '~/test'}})

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.24.0'
3+
__version__ = '4.25.0'
44
"""Version number.
55
66
:type: str

src/dependency_injector/containers.c

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)