2020-07-20 20:58:18 +00:00
|
|
|
.. _providers:
|
|
|
|
|
2015-06-10 06:53:15 +00:00
|
|
|
Providers
|
|
|
|
=========
|
|
|
|
|
2020-09-01 01:26:21 +00:00
|
|
|
Providers help to assemble the objects. They create objects and inject the dependencies.
|
2015-06-10 06:53:15 +00:00
|
|
|
|
2020-09-01 01:26:21 +00:00
|
|
|
Each provider is a callable. You call the provider like a function when you need to create an
|
|
|
|
object. Provider retrieves the underlying dependencies and inject them into the created object.
|
|
|
|
It causes the cascade effect that helps to assemble object graphs.
|
2015-07-27 22:31:19 +00:00
|
|
|
|
2020-09-01 01:26:21 +00:00
|
|
|
.. code-block:: bash
|
2015-06-10 06:53:15 +00:00
|
|
|
|
2020-09-01 01:26:21 +00:00
|
|
|
provider1()
|
|
|
|
│
|
|
|
|
├──> provider2()
|
|
|
|
│
|
|
|
|
├──> provider3()
|
|
|
|
│ │
|
|
|
|
│ └──> provider4()
|
|
|
|
│
|
|
|
|
└──> provider5()
|
|
|
|
│
|
|
|
|
└──> provider6()
|
|
|
|
|
|
|
|
Another providers feature is an overriding. Any of the providers can be overridden by another
|
|
|
|
provider. When provider is overridden it calls to the overriding provider instead of providing
|
|
|
|
the object by its own. This helps in testing. This also helps in overriding API clients with
|
2020-09-02 21:25:20 +00:00
|
|
|
stubs for the development or staging environment. See the example at :ref:`provider-overriding`.
|
2020-09-01 01:26:21 +00:00
|
|
|
|
|
|
|
Providers module API docs - :py:mod:`dependency_injector.providers`
|
2016-06-08 22:43:25 +00:00
|
|
|
|
2015-06-10 06:53:15 +00:00
|
|
|
.. toctree::
|
|
|
|
:maxdepth: 2
|
|
|
|
|
2015-06-16 07:37:57 +00:00
|
|
|
factory
|
|
|
|
singleton
|
2015-07-15 21:48:30 +00:00
|
|
|
callable
|
2018-10-18 16:39:19 +00:00
|
|
|
coroutine
|
2016-06-09 14:49:09 +00:00
|
|
|
object
|
2020-06-14 21:32:12 +00:00
|
|
|
list
|
2020-06-25 21:12:16 +00:00
|
|
|
configuration
|
2020-06-29 20:32:12 +00:00
|
|
|
selector
|
2017-12-21 20:54:44 +00:00
|
|
|
dependency
|
2015-07-21 06:57:13 +00:00
|
|
|
overriding
|
2020-08-21 01:52:12 +00:00
|
|
|
provided_instance
|
2015-07-27 22:31:19 +00:00
|
|
|
custom
|