-
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.
- Loading branch information
1 parent
10d0761
commit cf41ac7
Showing
12 changed files
with
59 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,5 @@ | |
members: | ||
- Wheke | ||
- Pod | ||
- Service | ||
- ServiceRegistry | ||
- aget_service | ||
- get_service |
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 |
---|---|---|
|
@@ -27,6 +27,7 @@ dependencies = [ | |
"pydantic", | ||
"pydantic-settings", | ||
"rich", | ||
"svcs", | ||
"typer", | ||
] | ||
|
||
|
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 |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.0.1a9" | ||
__version__ = "0.0.1a10" |
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
from wheke.core import Wheke | ||
from wheke.pod import Pod | ||
from wheke.service import Service, ServiceRegistry | ||
from wheke.service import aget_service, get_service | ||
|
||
__all__ = [ | ||
"Pod", | ||
"Wheke", | ||
"Service", | ||
"ServiceRegistry", | ||
"aget_service", | ||
"get_service", | ||
] |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,46 +1,19 @@ | ||
from abc import ABC | ||
from collections.abc import Callable | ||
from typing import ClassVar | ||
from typing import TypeVar | ||
|
||
from wheke.exceptions import ServiceTypeNotRegisteredError | ||
from svcs import Container, Registry | ||
|
||
T = TypeVar("T") | ||
|
||
class Service(ABC): | ||
""" | ||
The Service base class that all Wheke | ||
services must implement. | ||
""" | ||
_registry = Registry() | ||
|
||
pass | ||
|
||
def get_service_registry() -> Registry: | ||
return _registry | ||
|
||
class ServiceRegistry: | ||
""" | ||
ServiceRegistry used to register and get services. | ||
""" | ||
|
||
_registry: ClassVar[dict[type[Service], Callable[[], Service]]] = {} | ||
def get_service(service_type: type[T]) -> T: | ||
return Container(_registry).get(service_type) | ||
|
||
@classmethod | ||
def register( | ||
cls, | ||
service_type: type[Service], | ||
service_factory: Callable[[], Service], | ||
) -> None: | ||
""" | ||
Register a service by providing its class | ||
and the service factory callable. | ||
""" | ||
cls._registry[service_type] = service_factory | ||
|
||
@classmethod | ||
def get(cls, service_type: type[Service]) -> Service: | ||
""" | ||
Get a service by its class. | ||
""" | ||
service_factory = cls._registry.get(service_type) | ||
|
||
if not service_factory: | ||
raise ServiceTypeNotRegisteredError | ||
|
||
return service_factory() | ||
async def aget_service(service_type: type[T]) -> T: | ||
return await Container(_registry).aget(service_type) |
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 was deleted.
Oops, something went wrong.