diff --git a/docs/advanced_usage/index.rst b/docs/advanced_usage/index.rst new file mode 100644 index 00000000..a8c3c7b6 --- /dev/null +++ b/docs/advanced_usage/index.rst @@ -0,0 +1,28 @@ + +Advanced usage +============== + +Current section of documentation describes advanced usage of *Objects*. + +@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 +``objects.injections.KwArg`` injection. + +Any Python object will be injected *as is*, except *Objects* providers, +that will be called to provide injectable value. + +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 diff --git a/examples/advanced_usage/inject_decorator_simple.py b/examples/advanced_usage/inject_decorator_simple.py index 94d51896..2b1ddff2 100644 --- a/examples/advanced_usage/inject_decorator_simple.py +++ b/examples/advanced_usage/inject_decorator_simple.py @@ -1,4 +1,4 @@ -"""`@inject()` decorator simple example.""" +"""`@inject` decorator simple example.""" from objects.providers import Factory from objects.injections import KwArg