Skip to content

context

dev_tool.context

CONTEXT = AppContext() module-attribute

AppContext

A context object that holds shared dependencies.

This class encapsulates shared dependencies, such as configuration management and notifications that are used across the app.

The constructor for the AppContext class.

Initializes shared dependencies including configuration, notification service, event bus, and event manager.

Source code in dev_tool/context.py
def __init__(self) -> None:
    """
    The constructor for the AppContext class.

    Initializes shared dependencies including configuration, notification
    service, event bus, and event manager.
    """

    if not self._initialized:
        self._initialized = True

        self.configuration = ConfigManager()
        self.notification = NotificationService()
        self.event_bus = EventBus()
        self.event_manager = AppEventManager(self.event_bus)

configuration instance-attribute

notification instance-attribute

event_bus instance-attribute

event_manager instance-attribute

__new__

A class method that ensures singleton instance creation.

Returns:

  • The singleton AppContext instance.

Source code in dev_tool/context.py
def __new__(cls):
    """
    A class method that ensures singleton instance creation.

    :return: The singleton AppContext instance.
    """
    if cls._instance is None:
        cls._instance = super().__new__(cls)
        cls._instance._initialized = False

    return cls._instance

get_configuration_manager

A method that gets the configuration manager instance.

Returns:

Source code in dev_tool/context.py
def get_configuration_manager(self) -> ConfigManager:
    """
    A method that gets the configuration manager instance.

    :return: The configuration manager instance.
    """

    return self.configuration

get_event_bus

A method that gets the event bus instance.

Returns:

Source code in dev_tool/context.py
def get_event_bus(self) -> EventBus:
    """
    A method that gets the event bus instance.

    :return: The event bus instance.
    """

    return self.event_bus

get_event_manager

A method that gets the event manager instance.

Returns:

Source code in dev_tool/context.py
def get_event_manager(self) -> AppEventManager:
    """
    A method that gets the event manager instance.

    :return: The application event manager instance.
    """

    return self.event_manager

get_notification_manager

A method that creates and returns a notification manager instance.

Parameters:

  • terminal (Terminal) –

    The blessed Terminal instance for display operations.

Returns:

Source code in dev_tool/context.py
def get_notification_manager(self, terminal: Terminal) -> NotificationManager:
    """
    A method that creates and returns a notification manager instance.

    :param terminal: The blessed Terminal instance for display operations.
    :return: A configured notification manager instance.
    """

    notification_display = NotificationDisplay(terminal)
    notification_service = NotificationService()
    return NotificationManager(notification_display, notification_service)

get_notification_service

A method that gets the notification service instance.

Returns:

Source code in dev_tool/context.py
def get_notification_service(self) -> NotificationService:
    """
    A method that gets the notification service instance.

    :return: The notification service instance.
    """

    return self.notification