2015-12-15 17:49:07 +03:00
|
|
|
Specialization of catalogs
|
|
|
|
--------------------------
|
|
|
|
|
2016-06-03 00:48:06 +03:00
|
|
|
.. currentmodule:: dependency_injector.containers
|
2015-12-15 17:49:07 +03:00
|
|
|
|
|
|
|
:py:class:`DeclarativeCatalog` and :py:class:`DynamicCatalog` could be
|
|
|
|
specialized for any kind of needs via declaring its subclasses.
|
|
|
|
|
|
|
|
One of such `builtin` features is a limitation to
|
|
|
|
:py:class:`DeclarativeCatalog` (and :py:class:`DynamicCatalog`) provider type.
|
|
|
|
|
|
|
|
Next example shows usage of this feature with :py:class:`DeclarativeCatalog`
|
|
|
|
in couple with feature of :py:class:`dependency_injector.providers.Factory`
|
|
|
|
for limitation of its provided type:
|
|
|
|
|
|
|
|
|
|
|
|
Listing of `services.py`:
|
|
|
|
|
|
|
|
.. literalinclude:: ../../examples/catalogs/declarative_provider_type/services.py
|
|
|
|
:language: python
|
2016-04-11 10:43:02 +03:00
|
|
|
:linenos:
|
2015-12-15 17:49:07 +03:00
|
|
|
|
|
|
|
Listing of `catalog.py`:
|
|
|
|
|
|
|
|
.. literalinclude:: ../../examples/catalogs/declarative_provider_type/catalog.py
|
|
|
|
:language: python
|
2016-04-11 10:43:02 +03:00
|
|
|
:linenos:
|
2015-12-15 17:49:07 +03:00
|
|
|
|
|
|
|
Limitation to provider type could be used with :py:class:`DynamicCatalog`
|
|
|
|
as well.
|
|
|
|
|
|
|
|
Next example does the same that previous one, but use
|
|
|
|
:py:class:`DynamicCatalog` instead of :py:class:`DeclarativeCatalog`:
|
|
|
|
|
|
|
|
Listing of `services.py`:
|
|
|
|
|
|
|
|
.. literalinclude:: ../../examples/catalogs/dynamic_provider_type/services.py
|
|
|
|
:language: python
|
2016-04-11 10:43:02 +03:00
|
|
|
:linenos:
|
2015-12-15 17:49:07 +03:00
|
|
|
|
|
|
|
Listing of `catalog.py`:
|
|
|
|
|
|
|
|
.. literalinclude:: ../../examples/catalogs/dynamic_provider_type/catalog.py
|
|
|
|
:language: python
|
2016-04-11 10:43:02 +03:00
|
|
|
:linenos:
|