This commit is contained in:
Roman Mogylatov 2020-06-13 22:47:34 -04:00
parent c77737d32e
commit 568cbf01a0
5 changed files with 393 additions and 346 deletions

View File

@ -22,6 +22,7 @@ Providers package API docs - :py:mod:`dependency_injector.providers`
callable
coroutine
object
list
dependency
overriding
custom

34
docs/providers/list.rst Normal file
View File

@ -0,0 +1,34 @@
List providers
--------------
.. currentmodule:: dependency_injector.providers
:py:class:`List` provider provides a list of values.
.. literalinclude:: ../../examples/providers/list.py
:language: python
:lines: 23-29
:linenos:
:py:class:`List` provider is needed for injecting a list of dependencies. It handles
positional argument injections the same way as :py:class:`Factory` provider:
+ All providers (instances of :py:class:`Provider`) are called every time
when injection needs to be done.
+ Providers could be injected "as is" (delegated), if it is defined explicitly. Check out
:ref:`factory_providers_delegation`.
+ All other values are injected *"as is"*.
Full example:
.. literalinclude:: ../../examples/providers/list.py
:language: python
:emphasize-lines: 23-29
:linenos:
.. note::
Positional context argument injections and keyword argument injections are not
supported.
.. disqus::

View File

@ -34,3 +34,12 @@ if __name__ == '__main__':
assert isinstance(dispatcher.modules, list)
assert dispatcher.modules[0].name == 'm1'
assert dispatcher.modules[1].name == 'm2'
# Call of dispatcher_factory() is equivalent to:
dispatcher = Dispatcher(
modules=[
Module(name='m1'),
Module(name='m2'),
],
)

File diff suppressed because it is too large Load Diff

View File

@ -1970,8 +1970,11 @@ cdef class List(Provider):
"""List provider provides a list of values.
:py:class:`List` provider is needed for injecting a list of dependencies. It handles
positional argument injections the same way like :py:class:`Callable` and :py:class:`Factory`
providers. Keyword argument injections are not supported.
positional argument injections the same way as :py:class:`Callable` and :py:class:`Factory`
providers.
Positional context argument injections and keyword argument injections are not
supported.
.. code-block:: python