2016-06-06 08:26:53 +00:00
|
|
|
Dynamic containers
|
|
|
|
------------------
|
2015-11-16 11:28:27 +00:00
|
|
|
|
2016-06-02 21:48:06 +00:00
|
|
|
.. currentmodule:: dependency_injector.containers
|
2015-11-26 11:39:42 +00:00
|
|
|
|
2016-06-06 08:26:53 +00:00
|
|
|
:py:class:`DynamicContainer` is an inversion of control container with dynamic
|
|
|
|
structure. It should cover most of the cases when list of providers that
|
|
|
|
would be included in container is non-deterministic and depends on
|
|
|
|
application's flow or its configuration (container's structure could be
|
|
|
|
determined just after application will be started and will do some initial
|
|
|
|
work, like parsing list of container's providers from the configuration).
|
2015-11-26 11:39:42 +00:00
|
|
|
|
2016-06-06 08:26:53 +00:00
|
|
|
While :py:class:`DeclarativeContainer` acts on class-level,
|
|
|
|
:py:class:`DynamicContainer` does the same on instance-level.
|
2015-11-26 11:39:42 +00:00
|
|
|
|
2016-06-06 08:26:53 +00:00
|
|
|
Here is an simple example of defining dynamic container with several factories:
|
2015-11-26 11:39:42 +00:00
|
|
|
|
2016-06-06 08:26:53 +00:00
|
|
|
.. literalinclude:: ../../examples/containers/dynamic.py
|
2015-11-26 11:39:42 +00:00
|
|
|
:language: python
|
|
|
|
|
2016-06-06 08:26:53 +00:00
|
|
|
Next example demonstrates creation of dynamic container based on some
|
|
|
|
configuration:
|
2015-11-26 11:39:42 +00:00
|
|
|
|
2016-06-06 08:26:53 +00:00
|
|
|
.. literalinclude:: ../../examples/containers/dynamic_runtime_creation.py
|
2015-11-26 11:39:42 +00:00
|
|
|
:language: python
|
2017-02-28 20:08:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
.. disqus::
|