betty.service package

Subpackages

Submodules

Module contents

An API for providing application-wide services.

final class betty.service.Service

Bases: Generic

Wrap a service so it can be type-checked as such.

__init__(service: ServiceT) None
service: ServiceT
exception betty.service.ServiceAlreadyInitialized

Bases: ServiceError

A service was unexpectedly initialized already.

exception betty.service.ServiceError

Bases: RuntimeError

A service API error.

class betty.service.ServiceManager

Bases: Prop[ServiceProviderT, GetServiceT, Any], Generic

Manage a single service for a service provider.

__init__(factory: ServiceOrFactory[ServiceProviderT, ServiceT, FactoryServiceT], /)
final get(service_provider: ServiceProviderT, /) GetServiceT

Get the property value from the owner.

init_owner(service_provider: ServiceProviderT, /) None

Initialize the property on an owner.

final override(service_provider: ServiceProviderT, service: ServiceOrFactory[ServiceProviderT, ServiceT, FactoryServiceT], /) None

Override the service for the given service provider.

Calling this will prevent the existing factory from being called.

This MUST only be called from instance.__init__().

exception betty.service.ServiceNotYetInitialized

Bases: ServiceError

A service was unexpectedly not yet initialized.

class betty.service.ServiceProvider

Bases: HasProps

A service provider.

__init__(*args: Any, services: ServiceLevel, **kwargs: Any)
property services: ServiceLevel

The service level the services are provided for.