mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-27 12:04:00 +03:00
742e73af1a
* Add implementation and typing stubs * Add tests * Add typing tests * Refactor FactoryAggregate * Update changelog * Add Aggregate provider docs and example * Update cross links between Aggregate, Selector, and FactoryAggregate docs * Add wording improvements to the docs
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
from dependency_injector import providers
|
|
|
|
|
|
class Animal:
|
|
...
|
|
|
|
|
|
class Cat(Animal):
|
|
...
|
|
|
|
|
|
# Test 1: to check Aggregate provider
|
|
provider1: providers.Aggregate[str] = providers.Aggregate(
|
|
a=providers.Object("str1"),
|
|
b=providers.Object("str2"),
|
|
)
|
|
provider_a_1: providers.Provider[str] = provider1.a
|
|
provider_b_1: providers.Provider[str] = provider1.b
|
|
val1: str = provider1("a")
|
|
|
|
provider1_set_non_string_keys: providers.Aggregate[str] = providers.Aggregate()
|
|
provider1_set_non_string_keys.set_providers({Cat: providers.Object("str")})
|
|
provider_set_non_string_1: providers.Provider[str] = provider1_set_non_string_keys.providers[Cat]
|
|
|
|
provider1_new_non_string_keys: providers.Aggregate[str] = providers.Aggregate(
|
|
{Cat: providers.Object("str")},
|
|
)
|
|
factory_new_non_string_1: providers.Provider[str] = provider1_new_non_string_keys.providers[Cat]
|
|
|
|
provider1_no_explicit_typing = providers.Aggregate(a=providers.Object("str"))
|
|
provider1_no_explicit_typing_factory: providers.Provider[str] = provider1_no_explicit_typing.providers["a"]
|
|
provider1_no_explicit_typing_object: str = provider1_no_explicit_typing("a")
|