mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-25 19:14:00 +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".
|
||||
There are four types of static providers:
|
||||
|
||||
- ``Class``
|
||||
- ``Object``
|
||||
- ``Function``
|
||||
- ``Value``
|
||||
- ``di.Class``
|
||||
- ``di.Object``
|
||||
- ``di.Function``
|
||||
- ``di.Value``
|
||||
|
||||
All of them have the same behaviour, but usage of anyone is predicted by
|
||||
readability and providing object's type.
|
||||
|
|
|
@ -1,23 +1,20 @@
|
|||
"""`Static` providers example."""
|
||||
|
||||
from dependency_injector.providers import Class
|
||||
from dependency_injector.providers import Object
|
||||
from dependency_injector.providers import Function
|
||||
from dependency_injector.providers import Value
|
||||
import dependency_injector as di
|
||||
|
||||
|
||||
# Provides class - `object`:
|
||||
cls_provider = Class(object)
|
||||
cls_provider = di.Class(object)
|
||||
assert cls_provider() is object
|
||||
|
||||
# Provides object - `object()`:
|
||||
object_provider = Object(object())
|
||||
object_provider = di.Object(object())
|
||||
assert isinstance(object_provider(), object)
|
||||
|
||||
# Provides function - `len`:
|
||||
function_provider = Function(len)
|
||||
function_provider = di.Function(len)
|
||||
assert function_provider() is len
|
||||
|
||||
# Provides value - `123`:
|
||||
value_provider = Value(123)
|
||||
value_provider = di.Value(123)
|
||||
assert value_provider() == 123
|
||||
|
|
Loading…
Reference in New Issue
Block a user