python-dependency-injector/examples/catalogs/operating_with_providers.py

34 lines
1.2 KiB
Python
Raw Normal View History

2015-08-05 16:44:00 +03:00
"""Operating with catalog providers example."""
2015-08-31 16:31:38 +03:00
from dependency_injector.catalog import AbstractCatalog
from dependency_injector.providers import Factory
from dependency_injector.providers import Singleton
2015-08-05 16:44:00 +03:00
class Catalog(AbstractCatalog):
"""Providers catalog."""
provider1 = Factory(object)
2015-08-31 16:31:38 +03:00
""":type: (dependency_injector.Provider) -> object"""
2015-08-05 16:44:00 +03:00
provider2 = Factory(object)
2015-08-31 16:31:38 +03:00
""":type: (dependency_injector.Provider) -> object"""
2015-08-05 16:44:00 +03:00
provider3 = Singleton(object)
2015-08-31 16:31:38 +03:00
""":type: (dependency_injector.Provider) -> object"""
2015-08-05 16:44:00 +03:00
provider4 = Singleton(object)
2015-08-31 16:31:38 +03:00
""":type: (dependency_injector.Provider) -> object"""
2015-08-05 16:44:00 +03:00
# Making some asserts:
assert Catalog.providers == dict(provider1=Catalog.provider1,
provider2=Catalog.provider2,
provider3=Catalog.provider3,
provider4=Catalog.provider4)
assert Catalog.filter(Factory) == dict(provider1=Catalog.provider1,
provider2=Catalog.provider2)
assert Catalog.filter(Singleton) == dict(provider3=Catalog.provider3,
provider4=Catalog.provider4)