Portal Community

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

1

Request Created & Validated

Schema validation runs before any hooks. Invalid requests are rejected immediately.

2

Hook 1: RateLimitInteractionHook.OnBeforePublish

Blocks if user is being flooded. If blocked, throws — subsequent hooks do not run.

3

Hook 2..N: Custom Hooks OnBeforePublish

Run in registration order. Any hook can block — subsequent hooks do not run if blocked.

4

Hook N: AuditInteractionHook.OnBeforePublish

Records the publish event. Audit runs last so it only logs interactions that actually get delivered.

5

EdgeStream Delivery

After all hooks pass, the request is published to EdgeStream.

Post-Receive Hook Execution Order

1

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.

2

Hook 1..N: Registered Hooks OnAfterRespond

Run in registration order. Exceptions are caught and logged — the cycle continues regardless.

3

TaskCompletionSource Resolves

After all hooks complete, PublishAndWaitAsync() resolves with the response.

Hook Order Summary Table

PositionHookTypeCan Block?
1RateLimitInteractionHookPre-sendYes
2Custom permission hooksPre-sendYes
3Enrichment hooksPre-sendNo (but can modify request)
4AuditInteractionHook (pre-send side)Pre-sendNo
5MetricsInteractionHook (pre-send side)Pre-sendNo
[EdgeStream Delivery]
ResponseValidationHook (always first)Post-receiveYes (sends error ack)
6AuditInteractionHook (post-receive side)Post-receiveNo
7MetricsInteractionHook (post-receive side)Post-receiveNo
8Custom business hooksPost-receiveNo