Domain isolation: typed contracts, service registry, and composable wiring
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>
This commit is contained in:
@@ -42,6 +42,7 @@ def create_base_app(
|
||||
*,
|
||||
context_fn: Callable[[], Awaitable[dict]] | None = None,
|
||||
before_request_fns: Sequence[Callable[[], Awaitable[None]]] | None = None,
|
||||
domain_services_fn: Callable[[], None] | None = None,
|
||||
) -> Quart:
|
||||
"""
|
||||
Create a Quart app with shared infrastructure.
|
||||
@@ -57,7 +58,13 @@ def create_base_app(
|
||||
If not provided, a minimal default context is used.
|
||||
before_request_fns:
|
||||
Extra before-request hooks (e.g. cart_loader for the cart app).
|
||||
domain_services_fn:
|
||||
Callable that registers domain services on the shared registry.
|
||||
Each app provides its own — registering real impls for owned
|
||||
domains and stubs (or real impls) for others.
|
||||
"""
|
||||
if domain_services_fn is not None:
|
||||
domain_services_fn()
|
||||
app = Quart(
|
||||
name,
|
||||
static_folder=STATIC_DIR,
|
||||
@@ -144,11 +151,8 @@ def create_base_app(
|
||||
# --- startup ---
|
||||
@app.before_serving
|
||||
async def _startup():
|
||||
try:
|
||||
from glue.setup import register_glue_handlers
|
||||
register_glue_handlers()
|
||||
except ImportError:
|
||||
pass # glue submodule not present in this build context
|
||||
from shared.events.handlers import register_shared_handlers
|
||||
register_shared_handlers()
|
||||
await init_config()
|
||||
print(pretty())
|
||||
await _event_processor.start()
|
||||
|
||||
Reference in New Issue
Block a user