mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-12-01 22:14:04 +03:00
5358dd85f1
* Rework movie lister example app * Code style fix * Doc block fix * Update the container * Make second round of the refactoring * Rename name to title * Remove old movie lister docs from the examples * Add fixtures generator output on success * Update docblock in the entities module * Update example readme * Add CLI app tutorial * Update some wording in the other tutorials * Spread link to the tutorial * Fix code indentation issue
32 lines
953 B
ReStructuredText
32 lines
953 B
ReStructuredText
.. _selector-provider:
|
|
|
|
Selector providers
|
|
------------------
|
|
|
|
.. currentmodule:: dependency_injector.providers
|
|
|
|
:py:class:`Selector` provider selects provider based on the configuration value or other callable.
|
|
|
|
.. literalinclude:: ../../examples/providers/selector.py
|
|
:language: python
|
|
:emphasize-lines: 6-10
|
|
:lines: 3-5,14-20
|
|
|
|
:py:class:`Selector` provider has a callable called ``selector`` and a dictionary of providers.
|
|
|
|
The ``selector`` callable is provided as a first positional argument. It can be
|
|
:py:class:`Configuration` provider or any other callable. It has to return a string value.
|
|
This value is used as a key for selecting the provider from the dictionary of providers.
|
|
|
|
The providers are provided as keyword arguments. Argument name is used as a key for
|
|
selecting the provider.
|
|
|
|
Full example:
|
|
|
|
.. literalinclude:: ../../examples/providers/selector.py
|
|
:language: python
|
|
:emphasize-lines: 14-18
|
|
:lines: 3-
|
|
|
|
.. disqus::
|