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

24 lines
578 B
Python
Raw Normal View History

2015-11-13 16:58:29 +00:00
"""Declarative catalog example."""
2015-10-11 12:34:21 +00:00
2015-11-14 20:47:33 +00:00
from dependency_injector import catalogs
from dependency_injector import providers
2015-10-11 12:34:21 +00:00
2015-11-14 20:47:33 +00:00
class Catalog(catalogs.DeclarativeCatalog):
2015-10-11 12:34:21 +00:00
"""Providers catalog."""
2015-11-14 20:47:33 +00:00
factory1 = providers.Factory(object)
""":type: providers.Provider -> object"""
2015-10-11 12:34:21 +00:00
2015-11-14 20:47:33 +00:00
factory2 = providers.Factory(object)
""":type: providers.Provider -> object"""
2015-10-11 12:34:21 +00:00
# Creating some objects:
object1 = Catalog.factory1()
object2 = Catalog.factory2()
# Making some asserts:
assert object1 is not object2
assert isinstance(object1, object)
assert isinstance(object2, object)