mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-30 05:23:59 +03:00
47c79b2772
* Add prototype * Add example * Remove typing erros in Python 2.7 and 3.4 * Move resources example * Draft resources docs * Update resources docs * Fix repr * Rename dict provider test * Add more tests * Add tests + refactoring * Add more tests * Update tests to run only on 3.5+ * Update setup.py * Add typing tests * Update changelog * Fix generator iteration * Remove contextlib * Hotfix aiohttp issue * Move aiohttp fix to tox.ini * Move aiohttp fix to a different place in tox
55 lines
1.4 KiB
ReStructuredText
55 lines
1.4 KiB
ReStructuredText
.. _providers:
|
|
|
|
Providers
|
|
=========
|
|
|
|
Providers help to assemble the objects. They create objects and inject the dependencies.
|
|
|
|
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. See ``Factory``, ``Singleton``,
|
|
``Callable`` and other provider docs below.
|
|
|
|
.. code-block:: bash
|
|
|
|
provider1()
|
|
│
|
|
├──> provider2()
|
|
│
|
|
├──> provider3()
|
|
│ │
|
|
│ └──> provider4()
|
|
│
|
|
└──> provider5()
|
|
│
|
|
└──> provider6()
|
|
|
|
Another providers feature is an overriding. You can override any provider with another provider.
|
|
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`.
|
|
|
|
Providers module API docs - :py:mod:`dependency_injector.providers`
|
|
|
|
.. toctree::
|
|
:maxdepth: 2
|
|
|
|
factory
|
|
singleton
|
|
callable
|
|
coroutine
|
|
object
|
|
list
|
|
dict
|
|
configuration
|
|
resource
|
|
selector
|
|
dependency
|
|
overriding
|
|
provided_instance
|
|
custom
|
|
typing_mypy
|