Startup hooks

With the zayt.web.startup decorator, you can mark functions as hooks that will be called when the application starts. The functions will be called in the order they are discovered and if any of them raise an error, the application will not start.

from zayt.web import startup


@startup
def my_startup_hook():
    ...

Startup functions can receive services as parameters through the dependency injection system.

from zayt.di import service
from zayt.web import startup


@service
class OIDCService:
    async def oidc_discovery(self):
        ...


@startup
async def my_startup_hook(oidc_service: OIDCService):
    await oidc_service.oidc_discovery()

You can use the Inject annotation if you need a named service.

from typing import Annotated

from zayt.di import Inject, service
from zayt.web import startup


@service(name="provider")
class OIDCService:
    async def oidc_discovery(self):
        ...


@startup
async def my_startup_hook(
    oidc_service: Annotated[OIDCService, Inject("provider")]
):
    await oidc_service.oidc_discovery()