Add typed service contracts (Protocols + frozen DTOs) in shared/contracts/ for cross-domain communication. Each domain exposes a service interface (BlogService, CalendarService, MarketService, CartService) backed by SQL implementations in shared/services/. A singleton registry with has() guards enables composable startup — apps register their own domain service and stubs for absent domains. Absorbs glue layer: navigation, relationships, event handlers (login, container, order) now live in shared/ with has()-guarded service calls. Factory gains domain_services_fn parameter for per-app service registration. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
20 lines
607 B
Python
20 lines
607 B
Python
from __future__ import annotations
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from shared.events import register_handler
|
|
from shared.models.domain_event import DomainEvent
|
|
from shared.services.navigation import rebuild_navigation
|
|
|
|
|
|
async def on_child_attached(event: DomainEvent, session: AsyncSession) -> None:
|
|
await rebuild_navigation(session)
|
|
|
|
|
|
async def on_child_detached(event: DomainEvent, session: AsyncSession) -> None:
|
|
await rebuild_navigation(session)
|
|
|
|
|
|
register_handler("container.child_attached", on_child_attached)
|
|
register_handler("container.child_detached", on_child_detached)
|