Update object provider docs

This commit is contained in:
Roman Mogilatov 2016-06-09 17:49:09 +03:00
parent 9969bc4761
commit 486353bbea
5 changed files with 23 additions and 43 deletions

View File

@ -29,7 +29,7 @@ be thread safe.
factory
singleton
callable
object
external_dependency
static
overriding
custom

12
docs/providers/object.rst Normal file
View File

@ -0,0 +1,12 @@
Object providers
----------------
.. currentmodule:: dependency_injector.providers
:py:class:`Object` provider returns provided instance "as is"
Example:
.. literalinclude:: ../../examples/providers/object.py
:language: python
:linenos:

View File

@ -1,22 +0,0 @@
Static providers
----------------
.. currentmodule:: dependency_injector.providers
Static providers are family of providers that return their values "as is".
There are four types of static providers:
- :py:class:`Class`
- :py:class:`Object`
- :py:class:`Function`
- :py:class:`Value`
All of them have the same behaviour (inherited from
:py:class:`StaticProvider`), but usage of any is predicted by readability
and providing object's type.
Example:
.. literalinclude:: ../../examples/providers/static.py
:language: python
:linenos:

View File

@ -0,0 +1,10 @@
"""Object providers example."""
import dependency_injector.providers as providers
# Creating object provider:
object_provider = providers.Object(1)
# Making some asserts:
assert object_provider() == 1

View File

@ -1,20 +0,0 @@
"""Static providers example."""
import dependency_injector.providers as providers
# Provides class - `object`:
cls_provider = providers.Class(object)
assert cls_provider() is object
# Provides object - `object()`:
object_provider = providers.Object(object())
assert isinstance(object_provider(), object)
# Provides function - `len`:
function_provider = providers.Function(len)
assert function_provider() is len
# Provides value - `123`:
value_provider = providers.Value(123)
assert value_provider() == 123