-
-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
149 changed files
with
4,961 additions
and
1,730 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from inspect import Parameter, Signature | ||
from typing import Any, Dict, Tuple | ||
|
||
from litestar import Litestar, get | ||
from litestar.di import Provide | ||
from litestar.plugins import DIPlugin | ||
|
||
|
||
class MyBaseType: | ||
def __init__(self, param): | ||
self.param = param | ||
|
||
|
||
class MyDIPlugin(DIPlugin): | ||
def has_typed_init(self, type_: Any) -> bool: | ||
return issubclass(type_, MyBaseType) | ||
|
||
def get_typed_init(self, type_: Any) -> Tuple[Signature, Dict[str, Any]]: | ||
signature = Signature([Parameter(name="param", kind=Parameter.POSITIONAL_OR_KEYWORD)]) | ||
annotations = {"param": str} | ||
return signature, annotations | ||
|
||
|
||
@get("/", dependencies={"injected": Provide(MyBaseType, sync_to_thread=False)}) | ||
async def handler(injected: MyBaseType) -> str: | ||
return injected.param | ||
|
||
|
||
app = Litestar(route_handlers=[handler], plugins=[MyDIPlugin()]) | ||
|
||
# run: /?param=hello |
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.
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 litestar import Litestar | ||
from litestar.router import Router | ||
from litestar.static_files import create_static_files_router | ||
|
||
|
||
class MyRouter(Router): | ||
pass | ||
|
||
|
||
app = Litestar( | ||
route_handlers=[ | ||
create_static_files_router( | ||
path="/static", | ||
directories=["assets"], | ||
router_class=MyRouter, | ||
) | ||
] | ||
) |
Oops, something went wrong.