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