Skip to content

Commit 9e6622f

Browse files
committed
Add release notes for v1.0.0-alpha.3.
1 parent 2d9efb2 commit 9e6622f

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,42 @@ To contribute, create a pull request on the develop branch following the [git fl
139139

140140
## Release Notes
141141

142+
### [1.0.0-alpha.3](https://github.com/runemalm/py-dependency-injection/releases/tag/v1.0.0-alpha.3) (2024-03-02)
143+
144+
- **Breaking Change**: Restriction on `@inject` Decorator: Starting from this version, the `@inject` decorator can now only be used on static class methods and class methods. This change is introduced due to potential pitfalls associated with resolving and injecting dependencies directly into class instance methods using the dependency container.
145+
146+
**Reasoning:**
147+
148+
Resolving and injecting dependencies into instance methods can lead to unexpected behaviors and may violate the principles of dependency injection. Instance methods often rely on the state of the object, and injecting dependencies from the container directly can obscure the dependencies required for a method. Additionally, it may introduce difficulties in testing and make the code harder to reason about.
149+
150+
By restricting the usage of the `@inject` decorator to static and class methods, we aim to encourage a cleaner separation of concerns, making it more explicit when dependencies are injected and providing better clarity on the dependencies required by a method.
151+
152+
**Before:**
153+
```python
154+
class Foo:
155+
156+
@inject()
157+
def instance_method(self, transient_instance: SomeInterface, scoped_instance: AnotherInterface, singleton_instance: ThirdInterface):
158+
# ...
159+
```
160+
161+
**After:**
162+
```python
163+
class Foo:
164+
165+
@classmethod
166+
@inject()
167+
def class_method(cls, transient_instance: SomeInterface, scoped_instance: AnotherInterface, singleton_instance: ThirdInterface):
168+
# ...
169+
170+
@staticmethod
171+
@inject()
172+
def static_method(transient_instance: SomeInterface, scoped_instance: AnotherInterface, singleton_instance: ThirdInterface):
173+
# ...
174+
```
175+
176+
- Documentation Update: The documentation has been updated to reflect the new restriction on the usage of the `@inject` decorator. Users are advised to review the documentation for updated examples and guidelines regarding method injection.
177+
142178
### [1.0.0-alpha.2](https://github.com/runemalm/py-dependency-injection/releases/tag/v1.0.0-alpha.2) (2024-02-27)
143179

144180
- Python Version Support: Added support for Python versions 3.7, 3.9, 3.10, 3.11, and 3.12.

0 commit comments

Comments
 (0)