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

30 lines
866 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
-----------------
``@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.
``@inject`` decorator takes only argument that is supposed to be an
2015-08-31 16:31:38 +03:00
``dependency_injector.injections.KwArg`` injection.
2015-08-05 17:22:25 +03:00
2015-08-31 16:31:38 +03:00
Any Python object will be injected *as is*, except *Dependency Injector*
providers, that will be called to provide injectable value.
2015-08-05 17:22:25 +03:00
Example:
.. literalinclude:: ../../examples/advanced_usage/inject_decorator_simple.py
:language: python
Example of dependecy injection in Flask view:
.. literalinclude:: ../../examples/advanced_usage/inject_decorator_flask.py
:language: python