2015-09-02 18:56:32 +03:00
|
|
|
"""Static providers example."""
|
2015-04-14 23:17:53 +03:00
|
|
|
|
2015-11-23 16:03:30 +03:00
|
|
|
from dependency_injector import providers
|
2015-04-14 23:17:53 +03:00
|
|
|
|
|
|
|
|
2015-06-18 14:55:13 +03:00
|
|
|
# Provides class - `object`:
|
2015-11-23 16:03:30 +03:00
|
|
|
cls_provider = providers.Class(object)
|
2015-04-14 23:17:53 +03:00
|
|
|
assert cls_provider() is object
|
|
|
|
|
2015-06-18 14:55:13 +03:00
|
|
|
# Provides object - `object()`:
|
2015-11-23 16:03:30 +03:00
|
|
|
object_provider = providers.Object(object())
|
2015-04-14 23:17:53 +03:00
|
|
|
assert isinstance(object_provider(), object)
|
|
|
|
|
2015-06-18 14:55:13 +03:00
|
|
|
# Provides function - `len`:
|
2015-11-23 16:03:30 +03:00
|
|
|
function_provider = providers.Function(len)
|
2015-04-14 23:17:53 +03:00
|
|
|
assert function_provider() is len
|
|
|
|
|
2015-06-18 14:55:13 +03:00
|
|
|
# Provides value - `123`:
|
2015-11-23 16:03:30 +03:00
|
|
|
value_provider = providers.Value(123)
|
2015-04-14 23:17:53 +03:00
|
|
|
assert value_provider() == 123
|