mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-24 18:43:58 +03:00
32 lines
1022 B
Python
32 lines
1022 B
Python
"""Operating with catalog providers example."""
|
|
|
|
import dependency_injector as di
|
|
|
|
|
|
class Catalog(di.AbstractCatalog):
|
|
|
|
"""Providers catalog."""
|
|
|
|
provider1 = di.Factory(object)
|
|
""":type: (di.Provider) -> object"""
|
|
|
|
provider2 = di.Factory(object)
|
|
""":type: (di.Provider) -> object"""
|
|
|
|
provider3 = di.Singleton(object)
|
|
""":type: (di.Provider) -> object"""
|
|
|
|
provider4 = di.Singleton(object)
|
|
""":type: (di.Provider) -> object"""
|
|
|
|
|
|
# Making some asserts:
|
|
assert Catalog.providers == dict(provider1=Catalog.provider1,
|
|
provider2=Catalog.provider2,
|
|
provider3=Catalog.provider3,
|
|
provider4=Catalog.provider4)
|
|
assert Catalog.filter(di.Factory) == dict(provider1=Catalog.provider1,
|
|
provider2=Catalog.provider2)
|
|
assert Catalog.filter(di.Singleton) == dict(provider3=Catalog.provider3,
|
|
provider4=Catalog.provider4)
|