File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -110,6 +110,45 @@ attribute of the provider that you're going to inject.
110
110
111
111
.. note :: Any provider has a ``.provider`` attribute.
112
112
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
+
113
152
.. _factory-specialize-provided-type :
114
153
115
154
Specializing the provided type
You can’t perform that action at this time.
0 commit comments