python-dependency-injector/docs/advanced_usage/index.rst

29 lines
891 B
ReStructuredText
Raw Normal View History

2015-08-05 17:22:25 +03:00
Advanced usage
==============
2015-08-31 16:31:38 +03:00
Current section of documentation describes advanced usage of
*Dependency Injector*.
2015-08-05 17:22:25 +03:00
@inject decorator
-----------------
2015-09-02 12:23:01 +03:00
``@di.inject()`` decorator can be used for making *inline* dependency
injections. It *patches* decorated callable in such way that dependency
injection will be done during every call of decorated callable.
2015-08-05 17:22:25 +03:00
2015-09-02 12:23:01 +03:00
``@di.inject()`` decorator takes keyword argument, that will be injected
during every next call of decorated callback with the same name. Any Python
object will be injected *as is*, except ``di.Provider``'s, which will be
called to provide injectable values.
2015-08-05 17:22:25 +03:00
Example:
.. literalinclude:: ../../examples/advanced_usage/inject_decorator_simple.py
:language: python
2015-09-02 12:23:01 +03:00
Example of usage ``@di.inject()`` decorator with Flask:
2015-08-05 17:22:25 +03:00
.. literalinclude:: ../../examples/advanced_usage/inject_decorator_flask.py
:language: python