diff --git a/CHANGELOG.md b/CHANGELOG.md index 1877dda..20206d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ Opyoid follows [semver guidelines](https://semver.org) for versioning. ## Unreleased +## 2.0.2 +### Fixes +- Fixed an InjectException raised when trying to bind a class with a stringified parameter type + ## 2.0.1 ### Fixes - Fixed MultiBindings not using the correct provider when having multiple ItemBindings to Providers diff --git a/opyoid/provider_registry.py b/opyoid/provider_registry.py index 7bbd980..e37f86f 100644 --- a/opyoid/provider_registry.py +++ b/opyoid/provider_registry.py @@ -38,6 +38,7 @@ def get_provider(self, target: Target[InjectedT]) -> Optional[Provider[InjectedT ) ) if len(possible_target_types) == 1: + target.type = possible_target_types[0] # noinspection PyTypeChecker frozen_target = FrozenTarget(possible_target_types[0], target.named) elif possible_target_types: diff --git a/tests_e2e/test_injection.py b/tests_e2e/test_injection.py index 9fbd139..ad69d79 100644 --- a/tests_e2e/test_injection.py +++ b/tests_e2e/test_injection.py @@ -872,6 +872,24 @@ def __init__(self, my_param: MyClass): self.assertIsInstance(other_parent.my_param, MyClass) self.assertIs(parent.my_param, other_parent.my_param) + def test_injection_with_string_type_cache_2(self): + class MyParentClass: + def __init__(self, my_param: "MyClass"): + self.my_param = my_param + + class MyOtherParentClass: + def __init__(self, my_param: MyClass): + self.my_param = my_param + + injector = self.get_injector(MyOtherParentClass, MyParentClass, MyClass) + parent = injector.inject(MyParentClass) + self.assertIsInstance(parent, MyParentClass) + self.assertIsInstance(parent.my_param, MyClass) + other_parent = injector.inject(MyOtherParentClass) + self.assertIsInstance(other_parent, MyOtherParentClass) + self.assertIsInstance(other_parent.my_param, MyClass) + self.assertIs(parent.my_param, other_parent.my_param) + def test_private_module_multi_bind(self): class DependencyClass: pass