mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-24 02:24:02 +03:00
2513d1f600
* Add Selector provider * Add Selector provider example * Add tests for selector provider * Update changelog * Add pydocstyle ignore D101 for examples * Fix repr() test * Update changelog * Add D203,D213 to examples pydocstyle ignore * Add selector provider docs
29 lines
547 B
Python
29 lines
547 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),
|
|
)
|
|
|
|
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)
|