Skip to content

Commit

Permalink
Merge pull request #364 from spacemanspiff2007/patch-1
Browse files Browse the repository at this point in the history
Add scope property to container
  • Loading branch information
Tishka17 authored Feb 11, 2025
2 parents 45c11df + 97a29a0 commit 7975764
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/dishka/async_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def __init__(
self._exits: list[Exit] = []
self.close_parent = close_parent

@property
def scope(self) -> BaseScope:
return self.registry.scope

@property
def context(self) -> MutableMapping[DependencyKey, Any]:
warnings.warn(
Expand Down
4 changes: 4 additions & 0 deletions src/dishka/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def __init__(
self._exits: list[Exit] = []
self.close_parent = close_parent

@property
def scope(self) -> BaseScope:
return self.registry.scope

@property
def context(self) -> MutableMapping[DependencyKey, Any]:
warnings.warn(
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/container/test_enter_exit.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_int(self) -> int:
return 100

container = make_container(MyProvider(), start_scope=start_scope)
assert container.registry.scope is expected_scope
assert container.scope is expected_scope
a = container.get(ClassA)
assert a
assert a.dep == 100
Expand Down Expand Up @@ -66,7 +66,7 @@ def get_int(self) -> int:
return 100

container = make_async_container(MyProvider(), start_scope=start_scope)
assert container.registry.scope is expected_scope
assert container.scope is expected_scope
a = await container.get(ClassA)
assert a
assert a.dep == 100
Expand Down

0 comments on commit 7975764

Please sign in to comment.