2015-07-16 00:48:30 +03:00
|
|
|
Callable providers
|
|
|
|
------------------
|
|
|
|
|
2015-09-02 18:48:11 +03:00
|
|
|
``di.Callable`` provider is a provider that wraps particular callable with
|
2015-07-16 00:48:30 +03:00
|
|
|
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-09-02 18:48:11 +03:00
|
|
|
``di.Callable`` provider uses keyword argument injections. Keyword argument
|
|
|
|
injections are done by passing injectable values as keyword arguments during
|
|
|
|
call time.
|
2015-07-16 00:48:30 +03:00
|
|
|
|
2015-09-02 18:48:11 +03:00
|
|
|
Context keyword arguments have higher priority than keyword argument
|
|
|
|
injections.
|
2015-07-16 00:48:30 +03:00
|
|
|
|
|
|
|
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
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2015-09-02 18:48:11 +03:00
|
|
|
``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.
|
2015-07-20 19:31:31 +03:00
|
|
|
|
2015-09-02 18:48:11 +03:00
|
|
|
``di.Callable`` delegate could be created obviously using
|
|
|
|
``di.Delegate(di.Callable())`` or by calling ``di.Callable.delegate()`` method.
|
2015-07-20 19:31:31 +03:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
2015-08-03 15:49:55 +03:00
|
|
|
.. literalinclude:: ../../examples/providers/callable_delegation.py
|
|
|
|
:language: python
|