Hook Execution Order
Hooks run in the order they are registered. The order matters — rate limiting should run before audit logging (so blocked interactions aren't logged as valid publishes), and validation always runs first on response receipt.
Recommended Registration Order
// Program.cs — recommended hook registration order
builder.Services.AddInteractionHook<RateLimitInteractionHook>(); // 1st: Block flooding before anything else
builder.Services.AddInteractionHook<BusinessPermissionHook>(); // 2nd: Custom business permission check
builder.Services.AddInteractionHook<TraceEnrichmentHook>(); // 3rd: Enrich with trace context
builder.Services.AddInteractionHook<AuditInteractionHook>(); // 4th: Log (after checks pass)
builder.Services.AddInteractionHook<MetricsInteractionHook>(); // 5th: Metrics (last)
Pre-Send Hook Execution Order
Request Created & Validated
Schema validation runs before any hooks. Invalid requests are rejected immediately.
Hook 1: RateLimitInteractionHook.OnBeforePublish
Blocks if user is being flooded. If blocked, throws — subsequent hooks do not run.
Hook 2..N: Custom Hooks OnBeforePublish
Run in registration order. Any hook can block — subsequent hooks do not run if blocked.
Hook N: AuditInteractionHook.OnBeforePublish
Records the publish event. Audit runs last so it only logs interactions that actually get delivered.
EdgeStream Delivery
After all hooks pass, the request is published to EdgeStream.
Post-Receive Hook Execution Order
ResponseValidationHook (always first)
The built-in validation hook always runs first — it is not in the registered hook list. If validation fails, no other hooks run.
Hook 1..N: Registered Hooks OnAfterRespond
Run in registration order. Exceptions are caught and logged — the cycle continues regardless.
TaskCompletionSource Resolves
After all hooks complete, PublishAndWaitAsync() resolves with the response.
Hook Order Summary Table
| Position | Hook | Type | Can Block? |
|---|---|---|---|
| 1 | RateLimitInteractionHook | Pre-send | Yes |
| 2 | Custom permission hooks | Pre-send | Yes |
| 3 | Enrichment hooks | Pre-send | No (but can modify request) |
| 4 | AuditInteractionHook (pre-send side) | Pre-send | No |
| 5 | MetricsInteractionHook (pre-send side) | Pre-send | No |
| — | [EdgeStream Delivery] | — | — |
| — | ResponseValidationHook (always first) | Post-receive | Yes (sends error ack) |
| 6 | AuditInteractionHook (post-receive side) | Post-receive | No |
| 7 | MetricsInteractionHook (post-receive side) | Post-receive | No |
| 8 | Custom business hooks | Post-receive | No |