Skip to content

TransactionalBackend

Bases: Backend

Backend variant that provides transactional event handling support.

Registers additional services for managing listeners and dispatchers to enable in-transaction event processing.

Properties

in_transaction (Listeners): The current state of in transaction Listeners.

Source code in event_sourcery/_event_store/backend.py
class TransactionalBackend(Backend):
    """
    Backend variant that provides transactional event handling support.

    Registers additional services for managing listeners and dispatchers
    to enable in-transaction event processing.

    Properties:
        in_transaction (Listeners): The current state of in transaction Listeners.
    """

    def __init__(self) -> None:
        super().__init__()
        self[Listeners] = singleton(lambda _: Listeners())
        self[Dispatcher] = lambda c: Dispatcher(c[Serde], c[Listeners])

    @property
    def in_transaction(self) -> Listeners:
        """
        Returns the current instance of `Listeners` for transactional event handling.
        """
        return cast(Listeners, self[Listeners])

in_transaction: Listeners property

Returns the current instance of Listeners for transactional event handling.