2020-07-20 23:58:18 +03:00
|
|
|
.. _providers:
|
|
|
|
|
2015-06-10 09:53:15 +03:00
|
|
|
Providers
|
|
|
|
=========
|
|
|
|
|
2020-09-01 04:26:21 +03:00
|
|
|
Providers help to assemble the objects. They create objects and inject the dependencies.
|
2015-06-10 09:53:15 +03:00
|
|
|
|
2020-09-01 04:26:21 +03: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.
|
2020-09-03 04:15:06 +03:00
|
|
|
It causes the cascade effect that helps to assemble object graphs. See ``Factory``, ``Singleton``,
|
|
|
|
``Callable`` and other provider docs below.
|
2015-07-28 01:31:19 +03:00
|
|
|
|
2020-09-01 04:26:21 +03:00
|
|
|
.. code-block:: bash
|
2015-06-10 09:53:15 +03:00
|
|
|
|
2020-09-01 04:26:21 +03:00
|
|
|
provider1()
|
|
|
|
│
|
|
|
|
├──> provider2()
|
|
|
|
│
|
|
|
|
├──> provider3()
|
|
|
|
│ │
|
|
|
|
│ └──> provider4()
|
|
|
|
│
|
|
|
|
└──> provider5()
|
|
|
|
│
|
|
|
|
└──> provider6()
|
|
|
|
|
2020-09-10 05:23:14 +03:00
|
|
|
Another providers feature is an overriding. You can override any provider with another provider.
|
2020-09-03 04:15:06 +03:00
|
|
|
This helps in testing. This also helps in overriding API clients with stubs for the development
|
|
|
|
or staging environment. See the example at :ref:`provider-overriding`.
|
|
|
|
|
|
|
|
If you need to inject not the whole object but the parts see :ref:`provided-instance`.
|
|
|
|
|
|
|
|
To create a new provider see :ref:`create-provider`.
|
2020-09-01 04:26:21 +03:00
|
|
|
|
|
|
|
Providers module API docs - :py:mod:`dependency_injector.providers`
|
2016-06-09 01:43:25 +03:00
|
|
|
|
2015-06-10 09:53:15 +03:00
|
|
|
.. toctree::
|
|
|
|
:maxdepth: 2
|
|
|
|
|
2015-06-16 10:37:57 +03:00
|
|
|
factory
|
|
|
|
singleton
|
2015-07-16 00:48:30 +03:00
|
|
|
callable
|
2018-10-18 19:39:19 +03:00
|
|
|
coroutine
|
2016-06-09 17:49:09 +03:00
|
|
|
object
|
2020-06-15 00:32:12 +03:00
|
|
|
list
|
2020-10-22 21:49:39 +03:00
|
|
|
dict
|
2020-06-26 00:12:16 +03:00
|
|
|
configuration
|
2020-10-25 03:56:32 +03:00
|
|
|
resource
|
2022-01-10 03:21:31 +03:00
|
|
|
aggregate
|
2020-06-29 23:32:12 +03:00
|
|
|
selector
|
2017-12-21 23:54:44 +03:00
|
|
|
dependency
|
2015-07-21 09:57:13 +03:00
|
|
|
overriding
|
2020-08-21 04:52:12 +03:00
|
|
|
provided_instance
|
2021-02-09 15:34:46 +03:00
|
|
|
inject_self
|
2015-07-28 01:31:19 +03:00
|
|
|
custom
|
2021-01-11 03:26:15 +03:00
|
|
|
async
|
2020-09-14 03:32:21 +03:00
|
|
|
typing_mypy
|