Update example provided_instance.py

This commit is contained in:
Roman Mogylatov 2020-08-20 21:49:41 -04:00
parent 2de38bae1f
commit ab3ea221c7
3 changed files with 11 additions and 10 deletions

View File

@ -16,22 +16,23 @@ class Service:
class Client:
def __init__(self, value1, value2, value3):
def __init__(self, value1, value2, value3, value4):
self.value1 = value1
self.value2 = value2
self.value3 = value3
self.value4 = value4
service = providers.Singleton(Service)
client_factory = providers.Factory(
Client,
value1=service.provided.value,
value2=service.provided.values[0],
value3=service.provided.get_value.call(),
value1=service.provided[0],
value2=service.provided.value,
value3=service.provided.values[0],
value4=service.provided.get_value.call(),
)
if __name__ == '__main__':
client = client_factory()
assert client.value1 == client.value2 == client.value3 == 'foo'

View File

@ -80732,7 +80732,7 @@ static PyTypeObject __pyx_type_19dependency_injector_9providers_ProvidedInstance
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
"Provider that helps to inject attributes and items of the injected instance.\n\n You can use it like that:\n\n .. code-block:: python\n\n service = providers.Singleton(Service)\n\n client_factory = providers.Factory(\n Client,\n value1=service.provided.value,\n value2=service.provided.values[0],\n value3=service.provided.get_value.call(),\n )\n\n\n You should not create this provider directly. Get it from the ``.provided`` attribute of the\n injected provider. This attribute returns the :py:class:`ProvidedInstance` for that provider.\n\n Providers that have ``.provided`` attribute:\n\n - :py:class:`Callable` and its subclasses\n - :py:class:`Factory` and its subclasses\n - :py:class:`Singleton` and its subclasses\n - :py:class:`Object`\n - :py:class:`List`\n - :py:class:`Selector`\n - :py:class:`Dependency`\n ", /*tp_doc*/
"Provider that helps to inject attributes and items of the injected instance.\n\n You can use it like that:\n\n .. code-block:: python\n\n service = providers.Singleton(Service)\n\n client_factory = providers.Factory(\n Client,\n value1=service.provided[0],\n value2=service.provided.value,\n value3=service.provided.values[0],\n value4=service.provided.get_value.call(),\n )\n\n You should not create this provider directly. Get it from the ``.provided`` attribute of the\n injected provider. This attribute returns the :py:class:`ProvidedInstance` for that provider.\n\n Providers that have ``.provided`` attribute:\n\n - :py:class:`Callable` and its subclasses\n - :py:class:`Factory` and its subclasses\n - :py:class:`Singleton` and its subclasses\n - :py:class:`Object`\n - :py:class:`List`\n - :py:class:`Selector`\n - :py:class:`Dependency`\n ", /*tp_doc*/
__pyx_tp_traverse_19dependency_injector_9providers_ProvidedInstance, /*tp_traverse*/
__pyx_tp_clear_19dependency_injector_9providers_ProvidedInstance, /*tp_clear*/
0, /*tp_richcompare*/

View File

@ -2601,12 +2601,12 @@ cdef class ProvidedInstance(Provider):
client_factory = providers.Factory(
Client,
value1=service.provided.value,
value2=service.provided.values[0],
value3=service.provided.get_value.call(),
value1=service.provided[0],
value2=service.provided.value,
value3=service.provided.values[0],
value4=service.provided.get_value.call(),
)
You should not create this provider directly. Get it from the ``.provided`` attribute of the
injected provider. This attribute returns the :py:class:`ProvidedInstance` for that provider.