mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-24 02:24:02 +03:00
31 lines
1.0 KiB
ReStructuredText
31 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:
|
|
|
|
|
|
.. disqus::
|