-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: β¨ functions/generators as handler dependencies (#35)
- Loading branch information
1 parent
4968975
commit f31ae96
Showing
5 changed files
with
143 additions
and
10 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
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
53 changes: 53 additions & 0 deletions
53
tests/cfg/test_modules/rodi_route_dependencies_functions.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,53 @@ | ||
try: | ||
from typing import Annotated | ||
except ImportError: | ||
from typing_extensions import Annotated | ||
|
||
|
||
from typing import Union | ||
from uuid import uuid4 | ||
|
||
from pest.decorators.controller import controller | ||
from pest.decorators.handler import get | ||
from pest.decorators.module import module | ||
from pest.di import injected | ||
|
||
|
||
def who_am_i(user: Union[str, None] = None): | ||
return user if user else str(uuid4()) | ||
|
||
|
||
def yield_me(user: Union[str, None] = None): | ||
yield user if user else str(uuid4()) | ||
|
||
|
||
@controller('') | ||
class FooController: | ||
@get('/assigned') | ||
def assigned(self, me: str = injected(who_am_i)): | ||
return {'id': me} | ||
|
||
@get('/assigned-with-yield') | ||
def assign_with_yield(self, me: str = injected(yield_me)): | ||
return {'id': me} | ||
|
||
|
||
@controller('') | ||
class FooController39plus: | ||
@get('/assigned') | ||
def assigned(self, me: Annotated[str, injected(who_am_i)]): | ||
return {'id': me} | ||
|
||
@get('/assigned-with-yield') | ||
def assign_with_yield(self, me: Annotated[str, injected(yield_me)]): | ||
return {'id': me} | ||
|
||
|
||
@module(controllers=[FooController]) | ||
class FunctionsDependenciesModule: | ||
pass | ||
|
||
|
||
@module(controllers=[FooController39plus]) | ||
class FunctionsDependenciesModule39plus: | ||
pass |
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