2015-07-16 00:48:30 +03:00
|
|
|
Callable providers
|
|
|
|
------------------
|
|
|
|
|
|
|
|
``Callable`` provider is a provider that wraps particular callable with
|
|
|
|
some injections. Every call of this provider returns result of call of initial
|
|
|
|
callable.
|
|
|
|
|
2015-07-20 19:31:31 +03:00
|
|
|
Callable providers and injections
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2015-07-16 00:48:30 +03:00
|
|
|
``Callable`` provider uses ``KwArg`` injections. ``KwArg`` injections are
|
|
|
|
done by passing injectable values as keyword arguments during call time.
|
|
|
|
|
|
|
|
Context keyword arguments have higher priority than ``KwArg`` injections.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2015-07-25 00:51:14 +03:00
|
|
|
.. image:: /images/providers/callable.png
|
2015-07-16 00:48:30 +03:00
|
|
|
:width: 100%
|
|
|
|
:align: center
|
|
|
|
|
2015-08-03 15:49:55 +03:00
|
|
|
.. literalinclude:: ../../examples/providers/callable_injections.py
|
|
|
|
:language: python
|
2015-07-20 19:31:31 +03:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
``Callable`` delegate could be created obviously using
|
|
|
|
``Delegate(Callable())`` or by calling ``Callable.delegate()`` method.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2015-08-03 15:49:55 +03:00
|
|
|
.. literalinclude:: ../../examples/providers/callable_delegation.py
|
|
|
|
:language: python
|