18 lines
610 B
Python
18 lines
610 B
Python
from typing import Dict, Any
|
|
|
|
SERVICE_REGISTRY: Dict[str, Dict[str, Any]] = {}
|
|
|
|
|
|
def register_service(service_type: str, provider_name: str, implementation: Any):
|
|
SERVICE_REGISTRY.setdefault(service_type, {})[provider_name] = implementation
|
|
|
|
|
|
def get_service(service_type: str, provider_name: str):
|
|
provider_dict = SERVICE_REGISTRY.get(service_type, {})
|
|
service_class = provider_dict.get(provider_name)
|
|
if service_class is None:
|
|
raise ValueError(
|
|
f"未找到服务类型 '{service_type}' 和提供商 '{provider_name}' 对应的实现。"
|
|
)
|
|
return service_class
|