2020-08-16 05:09:41 +03:00
|
|
|
Dynamic container
|
|
|
|
-----------------
|
2015-11-16 14:28:27 +03:00
|
|
|
|
2016-06-03 00:48:06 +03:00
|
|
|
.. currentmodule:: dependency_injector.containers
|
2015-11-26 14:39:42 +03:00
|
|
|
|
2020-08-16 05:09:41 +03:00
|
|
|
:py:class:`DynamicContainer` is a collection of the providers defined in the runtime.
|
2015-11-26 14:39:42 +03:00
|
|
|
|
2020-08-16 05:09:41 +03:00
|
|
|
You create the dynamic container instance and put the providers as attributes.
|
2015-11-26 14:39:42 +03:00
|
|
|
|
2016-06-06 11:26:53 +03:00
|
|
|
.. literalinclude:: ../../examples/containers/dynamic.py
|
2015-11-26 14:39:42 +03:00
|
|
|
:language: python
|
2020-08-16 05:09:41 +03:00
|
|
|
:lines: 3-
|
|
|
|
|
|
|
|
The dynamic container is good for the case when your application structure depends on the
|
|
|
|
configuration file or some other source that you can reach only after application is already
|
|
|
|
running (database, api, etc).
|
2015-11-26 14:39:42 +03:00
|
|
|
|
2020-08-16 05:09:41 +03:00
|
|
|
In this example we use the configuration to fill in the dynamic container with the providers:
|
2015-11-26 14:39:42 +03:00
|
|
|
|
2016-06-06 11:26:53 +03:00
|
|
|
.. literalinclude:: ../../examples/containers/dynamic_runtime_creation.py
|
2015-11-26 14:39:42 +03:00
|
|
|
:language: python
|
2020-08-16 05:09:41 +03:00
|
|
|
:lines: 3-
|
2017-02-28 23:08:52 +03:00
|
|
|
|
|
|
|
.. disqus::
|
2020-08-16 05:09:41 +03:00
|
|
|
|