Update Callable provider docs

This commit is contained in:
Roman Mogilatov 2015-09-02 18:48:11 +03:00
parent 9326fdace4
commit 444af2ab0e
4 changed files with 23 additions and 26 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 38 KiB

View File

@ -1,17 +1,19 @@
Callable providers
------------------
``Callable`` provider is a provider that wraps particular callable with
``di.Callable`` provider is a provider that wraps particular callable with
some injections. Every call of this provider returns result of call of initial
callable.
Callable providers and injections
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
``Callable`` provider uses ``KwArg`` injections. ``KwArg`` injections are
done by passing injectable values as keyword arguments during call time.
``di.Callable`` provider uses keyword argument injections. Keyword argument
injections are done by passing injectable values as keyword arguments during
call time.
Context keyword arguments have higher priority than ``KwArg`` injections.
Context keyword arguments have higher priority than keyword argument
injections.
Example:
@ -25,13 +27,13 @@ Example:
Callable providers delegation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
``Callable`` provider could be delegated to any other provider via any kind of
injection. Delegation of ``Callable`` providers is the same as ``Factory`` and
``Singleton`` providers delegation, please follow *Factory providers
delegation* section for example.
``di.Callable`` provider could be delegated to any other provider via any kind
of injection. Delegation of ``di.Callable`` providers is the same as
``di.Factory`` and ``di.Singleton`` providers delegation, please follow
*Factory providers delegation* section for example.
``Callable`` delegate could be created obviously using
``Delegate(Callable())`` or by calling ``Callable.delegate()`` method.
``di.Callable`` delegate could be created obviously using
``di.Delegate(di.Callable())`` or by calling ``di.Callable.delegate()`` method.
Example:

View File

@ -1,15 +1,13 @@
"""`Callable` providers delegation example."""
"""`di.Callable` providers delegation example."""
import sys
from dependency_injector.providers import Callable
from dependency_injector.providers import Delegate
import dependency_injector as di
# Creating some callable provider and few delegates of it:
callable_provider = Callable(sys.exit)
callable_provider = di.Callable(sys.exit)
callable_provider_delegate1 = callable_provider.delegate()
callable_provider_delegate2 = Delegate(callable_provider)
callable_provider_delegate2 = di.Delegate(callable_provider)
# Making some asserts:
assert callable_provider_delegate1() is callable_provider

View File

@ -1,17 +1,14 @@
"""`Callable` providers example."""
from passlib.hash import sha256_crypt
from dependency_injector.providers import Callable
from dependency_injector.injections import KwArg
"""`di.Callable` providers example."""
import passlib.hash
import dependency_injector as di
# Password hasher and verifier providers (hash function could be changed
# anytime (for example, to sha512) without any changes in client's code):
password_hasher = Callable(sha256_crypt.encrypt,
KwArg('salt_size', 16),
KwArg('rounds', 10000))
password_verifier = Callable(sha256_crypt.verify)
password_hasher = di.Callable(passlib.hash.sha256_crypt.encrypt,
salt_size=16,
rounds=10000)
password_verifier = di.Callable(passlib.hash.sha256_crypt.verify)
# Making some asserts (client's code):
hashed_password = password_hasher('super secret')