Permalink
Fetching contributors…
Cannot retrieve contributors at this time
50 lines (35 sloc) 1.52 KB

Overriding of providers

.. currentmodule:: dependency_injector.providers

Every provider could be overridden by another provider.

This gives opportunity to make system behaviour more flexible at some point. The main feature is that while your code is using providers, it depends on providers, but not on the objects that providers provide. As a result of this, you can change providing by provider object to a different one, but still compatible one, without chaning your previously written code.

Provider overriding functionality has such interface:

/images/providers/provider_override.png

Example:

/images/providers/overriding_simple.png

.. literalinclude:: ../../examples/providers/overriding_simple.py
   :language: python
   :linenos:

Example:

/images/providers/overriding_users_model.png

.. literalinclude:: ../../examples/providers/overriding_users_model.py
   :language: python
   :linenos:


.. disqus::