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.
77From version 0.7.6 *Dependency Injector * framework strictly
88follows `Semantic versioning `_
99
10+ Development version
11+ -------------------
12+ - Add docs and example for ``Factory.add_attributes() `` method.
13+
10144.29.0
1115------
1216- 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:
4040 :language: python
4141 :lines: 3-
4242
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+
4351Passing arguments to the underlying providers
4452---------------------------------------------
4553
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