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

23 lines
570 B
Python
Raw Normal View History

2016-05-29 22:06:02 +03:00
"""Declarative IoC container simple example."""
2016-06-03 19:20:34 +03:00
import dependency_injector.containers as containers
import dependency_injector.providers as providers
2016-05-29 22:06:02 +03:00
# Defining declarative IoC container:
class Container(containers.DeclarativeContainer):
"""Example IoC container."""
factory1 = providers.Factory(object)
factory2 = providers.Factory(object)
# Creating some objects:
object1 = Container.factory1()
object2 = Container.factory2()
# Making some asserts:
assert object1 is not object2
assert isinstance(object1, object)
assert isinstance(object2, object)