-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use globals of the function; don't support local ctx; add tests in se…
…parated modules.
- Loading branch information
Showing
6 changed files
with
66 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
18 changes: 18 additions & 0 deletions
18
tests/container/mod_tests/provider_fn_deffered_dep_missuse.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from __future__ import annotations | ||
|
||
from aioinject.containers import Container | ||
from aioinject.providers import Singleton | ||
|
||
|
||
cont = Container() | ||
|
||
|
||
# notice that C is not defined yet | ||
def get_c() -> C: | ||
return C() | ||
|
||
|
||
cont.register(Singleton(get_c)) | ||
|
||
|
||
class C: ... |
31 changes: 31 additions & 0 deletions
31
tests/container/mod_tests/provider_fn_with_deffered_dep.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
|
||
from aioinject.containers import Container | ||
from aioinject.providers import Singleton | ||
|
||
|
||
@dataclass | ||
class B: | ||
a: A | ||
|
||
|
||
cont = Container() | ||
|
||
|
||
def get_b(a: A) -> B: | ||
return B(a) | ||
|
||
|
||
cont.register(Singleton(get_b)) | ||
|
||
|
||
class A: ... | ||
|
||
|
||
cont.register(Singleton(A)) | ||
with cont.sync_context() as ctx: | ||
a = ctx.resolve(A) | ||
b = ctx.resolve(B) | ||
assert b.a is a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters