python-dependency-injector/examples/providers/static.py

24 lines
620 B
Python
Raw Normal View History

2015-06-16 10:37:57 +03:00
"""`Static` providers example."""
2015-08-31 16:31:38 +03:00
from dependency_injector.providers import Class
from dependency_injector.providers import Object
from dependency_injector.providers import Function
from dependency_injector.providers import Value
2015-06-18 14:55:13 +03:00
# Provides class - `object`:
cls_provider = Class(object)
assert cls_provider() is object
2015-06-18 14:55:13 +03:00
# Provides object - `object()`:
object_provider = Object(object())
assert isinstance(object_provider(), object)
2015-06-18 14:55:13 +03:00
# Provides function - `len`:
function_provider = Function(len)
assert function_provider() is len
2015-06-18 14:55:13 +03:00
# Provides value - `123`:
value_provider = Value(123)
assert value_provider() == 123