Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix: allow factory method to get requested type as well as activating type #54

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Prev Previous commit
🐛 fix: handle resolving alias directly
  • Loading branch information
StummeJ committed Oct 18, 2024
commit d092b4b3e67d51fa8828f165cdb14a16a7d7f2df
7 changes: 7 additions & 0 deletions rodi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,13 @@ def get(
scope = ActivationScope(self)

resolver = self._map.get(desired_type)
if not resolver:
cls_name = class_name(desired_type)
resolver = (
self._map.get(cls_name)
or self._map.get(cls_name.lower())
or self._map.get(to_standard_param_name(cls_name))
)
scoped_service = scope.scoped_services.get(desired_type) if scope else None

if not resolver and not scoped_service:
Expand Down
3 changes: 3 additions & 0 deletions tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,9 @@ def resolve_derived_class(_) -> DerivedClass:
assert isinstance(u, UsingAliasByType)
assert isinstance(u.example, DerivedClass)

b = provider.get(BaseClass)
assert isinstance(b, DerivedClass)


def test_get_service_by_name_or_alias():
container = arrange_cats_example()
Expand Down
Loading