2015-10-11 15:34:21 +03:00
|
|
|
Overriding of catalogs
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
Catalogs can be overridden by other catalogs. This, actually, means that
|
|
|
|
all of the providers from overriding catalog will override providers with the
|
|
|
|
same names in overridden catalog.
|
|
|
|
|
|
|
|
There are two ways to override catalog by another catalog:
|
|
|
|
|
2015-11-10 11:42:29 +03:00
|
|
|
- Use ``di.DeclarativeCatalog.override(AnotherCatalog)`` method.
|
2015-10-11 15:34:21 +03:00
|
|
|
- Use ``@di.override(AnotherCatalog)`` class decorator.
|
|
|
|
|
2015-11-10 11:42:29 +03:00
|
|
|
Example of overriding catalog using ``di.DeclarativeCatalog.override()``
|
|
|
|
method:
|
2015-10-11 15:34:21 +03:00
|
|
|
|
|
|
|
.. literalinclude:: ../../examples/catalogs/override.py
|
|
|
|
:language: python
|
|
|
|
|
|
|
|
Example of overriding catalog using ``@di.override()`` decorator:
|
|
|
|
|
|
|
|
.. literalinclude:: ../../examples/catalogs/override_decorator.py
|
|
|
|
:language: python
|
|
|
|
|
2015-10-23 16:23:12 +03:00
|
|
|
Also there are several useful methods and properties that help to work with
|
|
|
|
catalog overridings:
|
|
|
|
|
2015-11-10 11:42:29 +03:00
|
|
|
- ``di.DeclarativeCatalog.is_overridden`` - read-only, evaluated in runtime,
|
2015-10-23 16:23:12 +03:00
|
|
|
property that is set to True if catalog is overridden.
|
2015-11-10 11:42:29 +03:00
|
|
|
- ``di.DeclarativeCatalog.last_overriding`` - reference to the last overriding
|
2015-10-23 16:23:12 +03:00
|
|
|
catalog, if any.
|
2015-11-10 11:42:29 +03:00
|
|
|
- ``di.DeclarativeCatalog.overridden_by`` - tuple of all overriding catalogs.
|
|
|
|
- ``di.DeclarativeCatalog.reset_last_overriding()`` - reset last overriding
|
2015-10-23 16:23:12 +03:00
|
|
|
catalog.
|
2015-11-10 11:42:29 +03:00
|
|
|
- ``di.DeclarativeCatalog.reset_override()`` - reset all overridings for all
|
2015-10-23 16:23:12 +03:00
|
|
|
catalog providers.
|