python-dependency-injector/docs/catalogs/bundles.rst

61 lines
2.1 KiB
ReStructuredText
Raw Normal View History

2015-11-13 19:58:29 +03:00
Catalog provider bundles
------------------------
2015-10-17 00:42:22 +03:00
2015-11-30 00:30:48 +03:00
.. currentmodule:: dependency_injector.catalogs
2015-11-20 14:46:57 +03:00
:py:class:`CatalogBundle` is a frozen, limited collection of catalog
providers. While catalog could be used as a centralized place for
particular providers group, such bundles of catalog providers can be used
for creating several frozen, limited scopes that could be passed to different
subsystems.
:py:class:`CatalogBundle` has API's parity with catalogs
(:py:class:`DeclarativeCatalog` or :py:class:`DynamicCatalog`) in terms of
retrieving the providers, but it is "frozen" in terms of modification
provider's list.
:py:class:`CatalogBundle` is considered to be dependable on catalogs
(:py:class:`DeclarativeCatalog` or :py:class:`DynamicCatalog`) entity by
its design.
Each catalog (:py:class:`DeclarativeCatalog` or :py:class:`DynamicCatalog`)
has a reference to its bundle class - :py:attr:`DeclarativeCatalog.Bundle`
(or :py:attr:`DynamicCatalog.Bundle` consequently). For example, subclass of
:py:class:`CatalogBundle` for some concrete declarative catalog
``SomeCatalog`` could be reached as ``SomeCatalog.Bundle``.
:py:class:`CatalogBundle` expects to get the list of its catalog providers
2015-10-17 00:42:22 +03:00
as positional arguments and will limit the scope of created bundle to this
list.
2015-11-20 14:46:57 +03:00
.. note::
Some notes about :py:class:`CatalogBundle` design.
Design and syntax of :py:class:`CatalogBundle` was developed with the idea
of keeping full functionalities of type-hinting and introspection of
modern IDE's. This design came from some practical experience of using
:py:class:`CatalogBundle` and considered to be the most comfortable for
developer.
2015-10-17 00:42:22 +03:00
Example:
.. image:: /images/catalogs/bundles.png
:width: 100%
:align: center
2015-10-19 11:39:34 +03:00
Listing of `services.py`:
.. literalinclude:: ../../examples/catalogs/bundles/services.py
:language: python
Listing of `views.py`:
.. literalinclude:: ../../examples/catalogs/bundles/views.py
:language: python
Listing of `catalogs.py`:
.. literalinclude:: ../../examples/catalogs/bundles/catalogs.py
2015-10-17 00:42:22 +03:00
:language: python