File tree Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Expand file tree Collapse file tree 3 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ that were made in every particular version.
7
7
From version 0.7.6 *Dependency Injector * framework strictly
8
8
follows `Semantic versioning `_
9
9
10
+ Development version
11
+ -------------------
12
+ - Add docs and example for ``Factory.add_attributes() `` method.
13
+
10
14
4.29.0
11
15
------
12
16
- Implement context manager interface for resetting a singleton provider.
Original file line number Diff line number Diff line change @@ -40,6 +40,14 @@ injected following these rules:
40
40
:language: python
41
41
:lines: 3-
42
42
43
+ ``Factory `` provider can inject attributes. Use ``.add_attributes() `` method to specify
44
+ attribute injections.
45
+
46
+ .. literalinclude :: ../../examples/providers/factory_attribute_injections.py
47
+ :language: python
48
+ :lines: 3-
49
+ :emphasize-lines: 18-18
50
+
43
51
Passing arguments to the underlying providers
44
52
---------------------------------------------
45
53
Original file line number Diff line number Diff line change
1
+ """`Factory` provider attribute injections example."""
2
+
3
+ from dependency_injector import containers , providers
4
+
5
+
6
+ class Client :
7
+ ...
8
+
9
+
10
+ class Service :
11
+ def __init__ (self ) -> None :
12
+ self .client = None
13
+
14
+
15
+ class Container (containers .DeclarativeContainer ):
16
+
17
+ client = providers .Factory (Client )
18
+
19
+ service = providers .Factory (Service )
20
+ service .add_attributes (clent = client )
21
+
22
+
23
+ if __name__ == '__main__' :
24
+ container = Container ()
25
+
26
+ service = container .service ()
27
+
28
+ assert isinstance (service .client , Client )
You can’t perform that action at this time.
0 commit comments