You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-**Tagged Constructor Injection**: Introduced support for constructor injection using the `Tagged`, `AnyTagged`, and `AllTagged` classes. This allows for seamless injection of dependencies that have been registered with specific tags, enhancing flexibility and control in managing your application's dependencies.
This example demonstrates how to use constructor injection to automatically inject tagged dependencies into your classes. By leveraging tags, you can group and categorize dependencies, enabling automatic injection based on specific criteria.
print(f"Primary port instance: {type(application.primary_ports[0]).__name__}") # Output: HttpAdapter
267
+
print(f"Secondary port instance: {type(application.secondary_ports[0]).__name__}") # Output: PostgresCarRepository
268
+
269
+
270
+
In this example, the `Application` class expects lists of instances tagged with `PrimaryPort` and `SecondaryPort`. By tagging and registering these dependencies, the container automatically injects the correct instances into the `Application` class when it is resolved.
271
+
272
+
Tags offer a powerful way to manage dependencies, ensuring that the right instances are injected based on your application's needs.
273
+
274
+
.. note::
275
+
You can also use the ``AnyTagged`` and ``AllTagged`` classes to inject dependencies based on more complex tagging logic. ``AnyTagged`` allows injection of any dependency matching one or more specified tags, while ``AllTagged`` requires the dependency to match all specified tags before injection. This provides additional flexibility in managing and resolving dependencies in your application.
Copy file name to clipboardExpand all lines: docs/releases.rst
+6
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,12 @@
6
6
Version History
7
7
###############
8
8
9
+
**1.0.0-alpha.10 (2024-08-11)**
10
+
11
+
- **Tagged Constructor Injection**: Introduced support for constructor injection using the `Tagged`, `AnyTagged`, and `AllTagged` classes. This allows for seamless injection of dependencies that have been registered with specific tags, enhancing flexibility and control in managing your application's dependencies.
12
+
13
+
`View release on GitHub <https://github.com/runemalm/py-dependency-injection/releases/tag/v1.0.0-alpha.10>`_
14
+
9
15
**1.0.0-alpha.9 (2024-08-08)**
10
16
11
17
- **Breaking Change**: Removed constructor injection when resolving dataclasses.
0 commit comments