🔔 Notifications & Handlers
Modern event handling with Bazario
🌟 What are Notifications?
Notifications in Bazario represent events that are published in response to certain actions. Think of them as messengers that broadcast changes throughout your system, without expecting a response back.
🛠️ Implementation Guide
📝 Example: Defining Notifications and Handlers
from bazario import Notification, NotificationHandler
from dataclasses import dataclass
@dataclass(frozen=True)
class PostAdded(Notification):
post_id: int
user_id: int
class PostAddedFirstHandler(NotificationHandler[PostAdded]):
def handle(self, notification: PostAdded) -> None:
logger.info(
"Post first added: post_id=%s, user_id=%s",
notification.post_id, notification.user_id,
)
class PostAddedSecondHandler(NotificationHandler[PostAdded]):
def handle(self, notification: PostAdded) -> None:
logger.info(
"Post second added: post_id=%s, user_id=%s",
notification.post_id, notification.user_id,
)
🔌 Setup Process
1️⃣ Register with Registry
2️⃣ Configure IoC Container 3️⃣ Publishing Notifications