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

32 lines
1022 B
Python
Raw Normal View History

2015-08-05 16:44:00 +03:00
"""Operating with catalog providers example."""
2015-09-02 00:24:19 +03:00
import dependency_injector as di
2015-08-05 16:44:00 +03:00
2015-09-02 00:24:19 +03:00
class Catalog(di.AbstractCatalog):
2015-08-05 16:44:00 +03:00
"""Providers catalog."""
2015-09-02 00:24:19 +03:00
provider1 = di.Factory(object)
""":type: (di.Provider) -> object"""
2015-08-05 16:44:00 +03:00
2015-09-02 00:24:19 +03:00
provider2 = di.Factory(object)
""":type: (di.Provider) -> object"""
2015-08-05 16:44:00 +03:00
2015-09-02 00:24:19 +03:00
provider3 = di.Singleton(object)
""":type: (di.Provider) -> object"""
2015-08-05 16:44:00 +03:00
2015-09-02 00:24:19 +03:00
provider4 = di.Singleton(object)
""":type: (di.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)
2015-09-02 00:24:19 +03:00
assert Catalog.filter(di.Factory) == dict(provider1=Catalog.provider1,
provider2=Catalog.provider2)
assert Catalog.filter(di.Singleton) == dict(provider3=Catalog.provider3,
provider4=Catalog.provider4)