mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 17:47:02 +03:00
Update factory and callable provider doc blocks
This commit is contained in:
parent
075e1bcf4f
commit
d9aac553c5
|
@ -19,9 +19,21 @@ class Callable(Provider):
|
||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
|
some_function = Callable(some_function,
|
||||||
|
'positional_arg1', 'positional_arg2',
|
||||||
|
keyword_argument1=3, keyword_argument=4)
|
||||||
|
|
||||||
|
# or
|
||||||
|
|
||||||
some_function = Callable(some_function) \
|
some_function = Callable(some_function) \
|
||||||
.args('arg1', 'arg2') \
|
.args('positional_arg1', 'positional_arg2') \
|
||||||
.kwargs(arg3=3, arg4=4)
|
.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')
|
__slots__ = ('_provides', '_args', '_kwargs')
|
||||||
|
|
|
@ -12,14 +12,35 @@ class Factory(Callable):
|
||||||
r""":py:class:`Factory` provider creates new instance on every call.
|
r""":py:class:`Factory` provider creates new instance on every call.
|
||||||
|
|
||||||
:py:class:`Factory` supports positional & keyword argument injections,
|
: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
|
.. code-block:: python
|
||||||
|
|
||||||
factory = Factory(SomeClass) \
|
factory = Factory(SomeClass) \
|
||||||
.args('arg1', 'arg2') \
|
.attributes(attribute1=1, attribute2=2)
|
||||||
.kwargs(arg3=3, arg4=4) \
|
|
||||||
.attributes(attribute1=5, attribute2=6)
|
|
||||||
|
|
||||||
Retrieving of provided instance can be performed via calling
|
Retrieving of provided instance can be performed via calling
|
||||||
:py:class:`Factory` object:
|
:py:class:`Factory` object:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user