2015-11-13 19:58:29 +03:00
|
|
|
Dynamic catalogs
|
|
|
|
----------------
|
2015-11-16 14:28:27 +03:00
|
|
|
|
2015-11-30 00:30:48 +03:00
|
|
|
.. currentmodule:: dependency_injector.catalogs
|
2015-11-26 14:39:42 +03:00
|
|
|
|
|
|
|
:py:class:`DynamicCatalog` is a catalog of providers that could be created in
|
|
|
|
application's runtime. It should cover most of the cases when list of
|
|
|
|
providers that would be included in catalog is non-deterministic in terms of
|
|
|
|
apllication code (catalog's structure could be determined just after
|
|
|
|
application will be started and will do some initial work, like parsing list
|
|
|
|
of catalog's providers from the configuration).
|
|
|
|
|
|
|
|
:py:class:`DeclarativeCatalog` and :py:class:`DynamicCatalog` have
|
|
|
|
100% API parity.
|
|
|
|
|
|
|
|
Main difference between :py:class:`DeclarativeCatalog` and
|
|
|
|
:py:class:`DynamicCatalog` is that :py:class:`DeclarativeCatalog` acts on
|
|
|
|
class-level, while :py:class:`DynamicCatalog` do the same on
|
|
|
|
instance-level.
|
|
|
|
|
|
|
|
Here is an simple example of defining dynamic catalog with several factories:
|
|
|
|
|
|
|
|
.. literalinclude:: ../../examples/catalogs/dynamic.py
|
|
|
|
:language: python
|
2016-04-11 10:43:02 +03:00
|
|
|
:linenos:
|
2015-11-26 14:39:42 +03:00
|
|
|
|
|
|
|
Next one example demonstrates creation and runtime filling of dynamic catalog:
|
|
|
|
|
|
|
|
.. literalinclude:: ../../examples/catalogs/dynamic_runtime_creation.py
|
|
|
|
:language: python
|
2016-04-11 10:43:02 +03:00
|
|
|
:linenos:
|