diff --git a/docs/images/providers/callable.png b/docs/images/providers/callable.png index 5dec3a65..4e3c20a2 100644 Binary files a/docs/images/providers/callable.png and b/docs/images/providers/callable.png differ diff --git a/docs/providers/callable.rst b/docs/providers/callable.rst index 625399e9..ce8b7be2 100644 --- a/docs/providers/callable.rst +++ b/docs/providers/callable.rst @@ -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: diff --git a/examples/providers/callable_delegation.py b/examples/providers/callable_delegation.py index 86f487a0..a4985982 100644 --- a/examples/providers/callable_delegation.py +++ b/examples/providers/callable_delegation.py @@ -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 diff --git a/examples/providers/callable_injections.py b/examples/providers/callable_injections.py index 3fcfac9c..339164ad 100644 --- a/examples/providers/callable_injections.py +++ b/examples/providers/callable_injections.py @@ -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')