python-dependency-injector/docs/containers/dynamic.rst
Roman Mogilatov 1eee0fe529 Update containers documentation
+ Refactor provider overriding system
2016-06-06 11:26:53 +03:00

28 lines
1.0 KiB
ReStructuredText

Dynamic containers
------------------
.. currentmodule:: dependency_injector.containers
: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).
While :py:class:`DeclarativeContainer` acts on class-level,
:py:class:`DynamicContainer` does the same on instance-level.
Here is an simple example of defining dynamic container with several factories:
.. literalinclude:: ../../examples/containers/dynamic.py
:language: python
:linenos:
Next example demonstrates creation of dynamic container based on some
configuration:
.. literalinclude:: ../../examples/containers/dynamic_runtime_creation.py
:language: python
:linenos: