Skip to content

Commit

Permalink
🐛 fix: handle resolving alias directly
Browse files Browse the repository at this point in the history
  • Loading branch information
StummeJ committed Oct 18, 2024
1 parent b16073a commit d092b4b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
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

0 comments on commit d092b4b

Please sign in to comment.