You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Foundatio.Mediator supports **cascading messages** through tuple return types, enabling elegant event choreography where handlers can trigger additional messages automatically. This is perfect for implementing event-driven workflows and the saga pattern.
185
+
186
+
### How Cascading Messages Work
187
+
188
+
When a handler returns a tuple, the mediator automatically:
189
+
190
+
1.**Returns the expected type** to the caller (if specified)
191
+
2.**Publishes remaining tuple items** as cascading events using `PublishAsync`
192
+
3.**Waits for completion** - all cascading messages are processed before the original call completes
193
+
194
+
### Example: Order Processing with Cascading Events
newOrderCreatedEvent(order.Id, order.CustomerEmail, order.Amount), // Published
269
+
newSendWelcomeEmail(order.CustomerEmail, "Valued Customer"), // Published
270
+
newUpdateInventory(order.ProductName, -1) // Published
271
+
);
272
+
}
273
+
}
274
+
```
275
+
181
276
## 🎪 Beautiful Middleware Pipeline
182
277
183
278
Create elegant middleware that runs before, after, and finally around your handlers. Middleware works seamlessly with the Result type for comprehensive error handling:
@@ -219,7 +314,7 @@ public static class ValidationMiddleware
219
314
{
220
315
if (MiniValidator.TryValidate(message, outvarerrors))
0 commit comments