diff --git a/docs/main/changelog.rst b/docs/main/changelog.rst index e9168312..4c851ae8 100644 --- a/docs/main/changelog.rst +++ b/docs/main/changelog.rst @@ -10,7 +10,7 @@ follows `Semantic versioning`_ Development version ------------------- - Update documentation and rework examples for: ``Singleton``, ``Callable``, ``Coroutine``, - ``Object`` providers. + ``Object``, ``List`` providers. 3.34.0 ------ diff --git a/docs/providers/list.rst b/docs/providers/list.rst index 4b92eeca..9ad4ece4 100644 --- a/docs/providers/list.rst +++ b/docs/providers/list.rst @@ -1,5 +1,10 @@ -List providers --------------- +List provider +------------- + +.. meta:: + :keywords: Python,DI,Dependency injection,IoC,Inversion of Control,List,Injection + :description: List provider helps to inject a list of the dependencies. This page demonstrates + how to use a List provider. .. currentmodule:: dependency_injector.providers @@ -7,28 +12,12 @@ List providers .. literalinclude:: ../../examples/providers/list.py :language: python - :emphasize-lines: 6-9 - :lines: 6-8, 23-29 - -: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"*. -+ Positional context arguments will be appended after :py:class:`List` positional injections. - -Full example: - -.. literalinclude:: ../../examples/providers/list.py - :language: python - :emphasize-lines: 23-26 :lines: 3- + :emphasize-lines: 19-22 + +``List`` provider handles positional arguments the same way as a :ref:`factory-provider`. .. note:: - - Keyword argument injections are not supported. + Keyword argument are not supported. .. disqus:: diff --git a/examples/providers/list.py b/examples/providers/list.py index cbf33bd6..1d2eb474 100644 --- a/examples/providers/list.py +++ b/examples/providers/list.py @@ -8,15 +8,11 @@ from dependency_injector import providers @dataclasses.dataclass class Module: - """Example module.""" - name: str @dataclasses.dataclass class Dispatcher: - """Example dispatcher.""" - modules: List[Module] @@ -28,6 +24,7 @@ dispatcher_factory = providers.Factory( ), ) + if __name__ == '__main__': dispatcher = dispatcher_factory() @@ -35,11 +32,10 @@ if __name__ == '__main__': 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'), - ], - ) + # Call "dispatcher = dispatcher_factory()" is an equivalent for: + # dispatcher = Dispatcher( + # modules=[ + # Module(name='m1'), + # Module(name='m2'), + # ], + # )