mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-26 19:43:58 +03:00
c4b33749d2
* Update callable provider docs * Update coroutine provider docs * Edit object docs * Edit list provider docs * Edit configuration provider docs * Edit selector provider docs * Fix mypy stub of the ``DeclarativeContainer`` to specify the ``__init__`` interface * Edit Dependency provider docs
30 lines
598 B
Python
30 lines
598 B
Python
"""`Selector` provider example."""
|
|
|
|
from dependency_injector import providers
|
|
|
|
|
|
class SomeClass:
|
|
...
|
|
|
|
|
|
class SomeOtherClass:
|
|
...
|
|
|
|
|
|
config = providers.Configuration()
|
|
|
|
selector = providers.Selector(
|
|
config.one_or_another,
|
|
one=providers.Factory(SomeClass),
|
|
another=providers.Factory(SomeOtherClass),
|
|
)
|
|
|
|
if __name__ == '__main__':
|
|
config.override({'one_or_another': 'one'})
|
|
instance_1 = selector()
|
|
assert isinstance(instance_1, SomeClass)
|
|
|
|
config.override({'one_or_another': 'another'})
|
|
instance_2 = selector()
|
|
assert isinstance(instance_2, SomeOtherClass)
|