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
Copy file name to clipboardExpand all lines: README.md
+58-12Lines changed: 58 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,7 @@ services.AddMediator();
33
33
34
34
## 🧩 Simple Handler Example
35
35
36
-
Just add any class ending with `Handler` or `Consumer`:
36
+
Just add a class (instance or static) ending with `Handler` or `Consumer`. Methods must be named `Handle(Async)` or `Consume(Async)`. First parameter is required and is always the message. Supports multiple handler methods in a single class—for example, a `UserHandler` containing handlers for all CRUD messages.
37
37
38
38
```csharp
39
39
publicrecordPing(stringText);
@@ -70,32 +70,39 @@ public class EmailHandler
70
70
71
71
## 🎪 Simple Middleware Example
72
72
73
-
Discovered by convention; static or instance with DI:
73
+
Just add a class (instance or static) ending with `Middleware`. Supports `Before(Async)`, `After(Async)` and `Finally(Async)` lifecycle events. First parameter is required and is always the message. Use `object` for all message types or an interface for a subset of messages. `HandlerResult` can be returned from the `Before` lifecycle method to enable short-circuiting message handling. Other return types from `Before` will be available as parameters to `After` and `Finally`.
Console.WriteLine($"Error in {msg.GetType().Name}: {ex.Message}");
103
+
log.LogInformation($"Error in {msg.GetType().Name}: {ex.Message}");
97
104
else
98
-
Console.WriteLine($"Handled {msg.GetType().Name} in {sw.ElapsedMilliseconds}ms");
105
+
log.LogInformation($"Handled {msg.GetType().Name} in {sw.ElapsedMilliseconds}ms");
99
106
}
100
107
}
101
108
```
@@ -105,7 +112,7 @@ public class LoggingMiddleware
105
112
Result\<T> is our built-in discriminated union for message-oriented workflows, capturing success, validation errors, conflicts, not found states, and more—without relying on exceptions.
0 commit comments