From d9aac553c5a48b1c6505511ed65b83e4e3ce393b Mon Sep 17 00:00:00 2001 From: Roman Mogilatov Date: Sun, 22 May 2016 14:57:25 +0300 Subject: [PATCH] Update factory and callable provider doc blocks --- dependency_injector/providers/callable.py | 16 ++++++++++-- dependency_injector/providers/creational.py | 29 ++++++++++++++++++--- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/dependency_injector/providers/callable.py b/dependency_injector/providers/callable.py index a26f10c6..7caffda5 100644 --- a/dependency_injector/providers/callable.py +++ b/dependency_injector/providers/callable.py @@ -19,9 +19,21 @@ class Callable(Provider): .. code-block:: python + some_function = Callable(some_function, + 'positional_arg1', 'positional_arg2', + keyword_argument1=3, keyword_argument=4) + + # or + some_function = Callable(some_function) \ - .args('arg1', 'arg2') \ - .kwargs(arg3=3, arg4=4) + .args('positional_arg1', 'positional_arg2') \ + .kwargs(keyword_argument1=3, keyword_argument=4) + + # or + + some_function = Callable(some_function) + some_function.args('positional_arg1', 'positional_arg2') + some_function.kwargs(keyword_argument1=3, keyword_argument=4) """ __slots__ = ('_provides', '_args', '_kwargs') diff --git a/dependency_injector/providers/creational.py b/dependency_injector/providers/creational.py index b5ba7c76..785c3471 100644 --- a/dependency_injector/providers/creational.py +++ b/dependency_injector/providers/creational.py @@ -12,14 +12,35 @@ class Factory(Callable): r""":py:class:`Factory` provider creates new instance on every call. :py:class:`Factory` supports positional & keyword argument injections, - as well as attribute injections: + as well as attribute injections. + + Positional and keyword argument injections could be defined like this: + + .. code-block:: python + + factory = Factory(SomeClass, + 'positional_arg1', 'positional_arg2', + keyword_argument1=3, keyword_argument=4) + + # or + + factory = Factory(SomeClass) \ + .args('positional_arg1', 'positional_arg2') \ + .kwargs(keyword_argument1=3, keyword_argument=4) + + # or + + factory = Factory(SomeClass) + factory.args('positional_arg1', 'positional_arg2') + factory.kwargs(keyword_argument1=3, keyword_argument=4) + + + Attribute injections are defined by using :py:meth:`Factory.attributes`: .. code-block:: python factory = Factory(SomeClass) \ - .args('arg1', 'arg2') \ - .kwargs(arg3=3, arg4=4) \ - .attributes(attribute1=5, attribute2=6) + .attributes(attribute1=1, attribute2=2) Retrieving of provided instance can be performed via calling :py:class:`Factory` object: