2016-06-06 11:26:53 +03:00
|
|
|
Dynamic containers
|
|
|
|
------------------
|
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
|
|
|
|
2016-06-06 11:26:53 +03: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 14:39:42 +03:00
|
|
|
|
2016-06-06 11:26:53 +03:00
|
|
|
While :py:class:`DeclarativeContainer` acts on class-level,
|
|
|
|
:py:class:`DynamicContainer` does the same on instance-level.
|
2015-11-26 14:39:42 +03:00
|
|
|
|
2016-06-06 11:26:53 +03:00
|
|
|
Here is an simple example of defining dynamic container with several factories:
|
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
|
2016-04-11 10:43:02 +03:00
|
|
|
:linenos:
|
2015-11-26 14:39:42 +03:00
|
|
|
|
2016-06-06 11:26:53 +03:00
|
|
|
Next example demonstrates creation of dynamic container based on some
|
|
|
|
configuration:
|
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
|
2016-04-11 10:43:02 +03:00
|
|
|
:linenos:
|
2017-02-28 23:08:52 +03:00
|
|
|
|
|
|
|
|
|
|
|
.. disqus::
|