Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/guacs/litestar-svcs
A plugin for Litestar to integrate `svcs`.
https://github.com/guacs/litestar-svcs
litestar svcs
Last synced: 4 months ago
JSON representation
A plugin for Litestar to integrate `svcs`.
- Host: GitHub
- URL: https://github.com/guacs/litestar-svcs
- Owner: guacs
- Created: 2023-11-21T11:30:27.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-30T13:25:15.000Z (about 1 year ago)
- Last Synced: 2024-08-03T17:12:35.469Z (7 months ago)
- Topics: litestar, svcs
- Language: Python
- Homepage:
- Size: 31.3 KB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-litestar - `litestar-svcs` - A plugin for the [SVCS](https://github.com/hynek/svcs) service locater/dependency injection library.<sup>*</sup> (Third-Party Extensions / General)
README
# Litestar Svcs
A plugin to integrate [litestar](https://github.com/litestar-org/litestar) with [svcs](https://github.com/hynek/svcs/).
# Basic Usage
```python
from litestar import Litestar
from litestar import get
from litestar_svcs import SvcsPlugin, SvcsPluginConfigfrom svcs import Container, Registry
@get("/", sync_to_thread=False)
def get_user(svcs_container: Container) -> int:
return svcs_container.get(int)registry = Registry()
registry.register_factory(int, lambda: 10)svcs_plugin_config = SvcsPluginConfig(registry=registry)
svcs_plugin = SvcsPlugin(svcs_plugin_config)app = Litestar([get_user], plugins=[svcs_plugin])
```# Configuring
- You can pass in the `registry` instance, as in the example, to the config or you can give it a callable (sync or async) and it will be used to create the registry when the app is starting.
- You can give a custom name to the name of the kwarg for injecting the containers by setting a different value for `container_dependency_key` (default is `svcs_container`).NOTE: You *cannot* configure the name of the kwarg which injects the registry (the kwarg name is `svcs_registry`).