2020-08-16 07:53:37 +03:00
|
|
|
Specialization of the container provider type
|
|
|
|
---------------------------------------------
|
2015-12-15 17:49:07 +03:00
|
|
|
|
2016-06-03 00:48:06 +03:00
|
|
|
.. currentmodule:: dependency_injector.containers
|
2015-12-15 17:49:07 +03:00
|
|
|
|
2020-08-16 07:53:37 +03:00
|
|
|
You can make a restriction of the :py:class:`DeclarativeContainer` provider type:
|
2015-12-15 17:49:07 +03:00
|
|
|
|
2016-06-06 11:26:53 +03:00
|
|
|
.. literalinclude:: ../../examples/containers/declarative_provider_type.py
|
2015-12-15 17:49:07 +03:00
|
|
|
:language: python
|
2020-08-16 07:53:37 +03:00
|
|
|
: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
|
|
|
|
2020-08-16 07:53:37 +03:00
|
|
|
The same works for the :py:class:`DynamicContainer`:
|
2015-12-15 17:49:07 +03:00
|
|
|
|
2016-06-06 11:26:53 +03:00
|
|
|
.. literalinclude:: ../../examples/containers/dynamic_provider_type.py
|
2015-12-15 17:49:07 +03:00
|
|
|
:language: python
|
2020-08-16 07:53:37 +03:00
|
|
|
:lines: 3-
|
|
|
|
:emphasize-lines: 23
|
2017-02-28 23:08:52 +03:00
|
|
|
|
2020-08-16 07:53:37 +03:00
|
|
|
The emphasized line will also cause an error.
|
2017-02-28 23:08:52 +03:00
|
|
|
|
|
|
|
.. disqus::
|