Skip to content

Commit a40b380

Browse files
committed
Update docs
1 parent 9fa76c0 commit a40b380

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

docs/providers/factory.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,45 @@ attribute of the provider that you're going to inject.
110110

111111
.. note:: Any provider has a ``.provider`` attribute.
112112

113+
.. _factory-string-imports:
114+
115+
String imports
116+
--------------
117+
118+
``Factory`` provider can handle string imports:
119+
120+
.. code-block:: python
121+
122+
class Container(containers.DeclarativeContainer):
123+
124+
service = providers.Factory("myapp.mypackage.mymodule.Service")
125+
126+
You can also make a relative import:
127+
128+
.. code-block:: python
129+
130+
# in myapp/container.py
131+
132+
class Container(containers.DeclarativeContainer):
133+
134+
service = providers.Factory(".mypackage.mymodule.Service")
135+
136+
or import a member of the current module just specifying its name:
137+
138+
.. code-block:: python
139+
140+
class Service:
141+
...
142+
143+
144+
class Container(containers.DeclarativeContainer):
145+
146+
service = providers.Factory("Service")
147+
148+
.. note::
149+
``Singleton``, ``Callable``, ``Resource``, and ``Coroutine`` providers handle string imports
150+
the same way as a ``Factory`` provider.
151+
113152
.. _factory-specialize-provided-type:
114153

115154
Specializing the provided type

0 commit comments

Comments
 (0)