mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-29 13:04:02 +03:00
Update static providers docs
This commit is contained in:
parent
a7ca196ee0
commit
a9eedc6760
|
@ -4,10 +4,10 @@ Static providers
|
||||||
Static providers are family of providers that return their values "as is".
|
Static providers are family of providers that return their values "as is".
|
||||||
There are four types of static providers:
|
There are four types of static providers:
|
||||||
|
|
||||||
- ``Class``
|
- ``di.Class``
|
||||||
- ``Object``
|
- ``di.Object``
|
||||||
- ``Function``
|
- ``di.Function``
|
||||||
- ``Value``
|
- ``di.Value``
|
||||||
|
|
||||||
All of them have the same behaviour, but usage of anyone is predicted by
|
All of them have the same behaviour, but usage of anyone is predicted by
|
||||||
readability and providing object's type.
|
readability and providing object's type.
|
||||||
|
|
|
@ -1,23 +1,20 @@
|
||||||
"""`Static` providers example."""
|
"""`Static` providers example."""
|
||||||
|
|
||||||
from dependency_injector.providers import Class
|
import dependency_injector as di
|
||||||
from dependency_injector.providers import Object
|
|
||||||
from dependency_injector.providers import Function
|
|
||||||
from dependency_injector.providers import Value
|
|
||||||
|
|
||||||
|
|
||||||
# Provides class - `object`:
|
# Provides class - `object`:
|
||||||
cls_provider = Class(object)
|
cls_provider = di.Class(object)
|
||||||
assert cls_provider() is object
|
assert cls_provider() is object
|
||||||
|
|
||||||
# Provides object - `object()`:
|
# Provides object - `object()`:
|
||||||
object_provider = Object(object())
|
object_provider = di.Object(object())
|
||||||
assert isinstance(object_provider(), object)
|
assert isinstance(object_provider(), object)
|
||||||
|
|
||||||
# Provides function - `len`:
|
# Provides function - `len`:
|
||||||
function_provider = Function(len)
|
function_provider = di.Function(len)
|
||||||
assert function_provider() is len
|
assert function_provider() is len
|
||||||
|
|
||||||
# Provides value - `123`:
|
# Provides value - `123`:
|
||||||
value_provider = Value(123)
|
value_provider = di.Value(123)
|
||||||
assert value_provider() == 123
|
assert value_provider() == 123
|
||||||
|
|
Loading…
Reference in New Issue
Block a user