Service

class asab.Service(app)[source]

Service objects are registered at the service registry, managed by an application object. See Application.Services for more details.

An example of a typical service class skeleton:

class MyService(asab.Service):

    def __init__(self, app, service_name):
        super().__init__(app, service_name)
        ...

    async def initialize(self, app):
        ...


    async def finalize(self, app):
        ...


    def service_method(self):
        ....

This is how a service is created and registered:

mysvc = MyService(app, "my_service")

This is how a service is located and used:

mysvc = app.get_service("my_service")
mysvc.service_method()
Service.Name

Each service is identified by its name.

Service.App

A reference to an Application object instance.

Lifecycle

Service.initialize(app)[source]

Called when the service is initialized. It can be overriden by an user.

Service.finalize(app)[source]

Called when the service is finalized e.g. during application exit-time. It can be overriden by an user.