python-dependency-injector/docs/containers/specialization.rst

26 lines
775 B
ReStructuredText
Raw Permalink Normal View History

Specialization of the container provider type
---------------------------------------------
2015-12-15 17:49:07 +03:00
.. currentmodule:: dependency_injector.containers
2015-12-15 17:49:07 +03:00
You can make a restriction of the :py:class:`DeclarativeContainer` provider type:
2015-12-15 17:49:07 +03:00
.. literalinclude:: ../../examples/containers/declarative_provider_type.py
2015-12-15 17:49:07 +03:00
:language: python
:lines: 3-
:emphasize-lines: 29-31
The emphasized lines will cause an error because ``other_provider`` is not a subtype of the
``ServiceProvider``. This helps to control the content of the container.
2015-12-15 17:49:07 +03:00
The same works for the :py:class:`DynamicContainer`:
2015-12-15 17:49:07 +03:00
.. literalinclude:: ../../examples/containers/dynamic_provider_type.py
2015-12-15 17:49:07 +03:00
:language: python
:lines: 3-
:emphasize-lines: 23
The emphasized line will also cause an error.
.. disqus::