ServiceBase
What it is
- A small base class for services that need access to an engine-provided
Servicescontainer. - Supports “wiring” dependencies after instantiation and provides a guard to ensure wiring happened.
Public API
class ServiceBase__init__(self) -> None- Initializes the service with no wired services (
_services = None).
- Initializes the service with no wired services (
set_services(self, services: IEngine.Services) -> None- Wires an
IEngine.Servicescontainer into the service.
- Wires an
services_wired(self) -> bool(property)- Returns
Trueif services have been wired; otherwiseFalse.
- Returns
services(self) -> IEngine.Services(property)- Returns the wired services container.
- Raises an
AssertionErrorif services are not wired.
Configuration/Dependencies
- Type dependency (for typing only):
naas_abi_core.engine.IEngine.IEngine, specificallyIEngine.Services. - No runtime imports from
IEnginedue toTYPE_CHECKING.
Usage
from naas_abi_core.services.ServiceBase import ServiceBase
class MyService(ServiceBase):
def do_something(self):
# Access wired services
return self.services # replace with actual service usage
svc = MyService()
assert not svc.services_wired
# Later: wire dependencies (engine would typically do this)
services_container = object() # placeholder for IEngine.Services
svc.set_services(services_container)
assert svc.services_wired
_ = svc.services
Caveats
- Accessing
servicesbefore callingset_services(...)triggers:AssertionError: Services are not wired.