@@ -10,11 +10,11 @@ Foundatio.Mediator is a high-performance, convention-based mediator library that
1010
1111## ✨ Why Choose Foundatio.Mediator?
1212
13- - ** 🚀 Blazing Fast** - Only 2x slower than direct method calls, 3x faster than MediatR
13+ - ** 🚀 Blazing Fast** - Nearly as fast as direct method calls, 3x faster than MediatR
1414- ** 🎯 Convention-Based** - No interfaces or base classes required
1515- ** ⚡ Source Generated** - Compile-time code generation for optimal performance
1616- ** 🔧 Full DI Integration** - Works seamlessly with Microsoft.Extensions.DependencyInjection
17- - ** 🎪 Middleware Pipeline** - Elegant middleware support with logging, timing, and custom logic
17+ - ** 🎪 Middleware Pipeline** - Elegant middleware support
1818- ** 📦 Auto Registration** - Handlers discovered and registered automatically
1919- ** 🔒 Compile-Time Safety** - Rich diagnostics catch errors before runtime
2020- ** 🔧 C# Interceptors** - Direct method calls using cutting-edge C# interceptor technology
@@ -67,7 +67,7 @@ var mediator = serviceProvider.GetRequiredService<IMediator>();
6767await mediator .InvokeAsync (new PingCommand (" 123" ));
6868
6969// Request/response
70- var greeting = await mediator .InvokeAsync <string >(new GreetingQuery (" World" ));
70+ var greeting = mediator .Invoke <string >(new GreetingQuery (" World" ));
7171Console .WriteLine (greeting ); // "Hello, World!"
7272```
7373
@@ -107,30 +107,21 @@ public class LoggingMiddleware
107107 }
108108}
109109
110- public class GlobalMiddleware
110+ public class ValidationMiddleware
111111{
112- public ( DateTime Date , TimeSpan Time ) Before (object message , CancellationToken cancellationToken )
112+ public HandlerResult Before (object message )
113113 {
114- Console .WriteLine ($" 🌍 Processing {message .GetType ().Name }" );
115- return (DateTime .UtcNow , DateTime .UtcNow .TimeOfDay );
116- }
117-
118- public async Task After (object message , DateTime start , TimeSpan time ,
119- IEmailService emailService , CancellationToken cancellationToken )
120- {
121- await emailService .SendEmailAsync (" audit@company.com" , " Message Processed" ,
122- $" Message {message .GetType ().Name } processed at {start }" );
123- Console .WriteLine ($" 🌍 Completed {message .GetType ().Name }" );
124- }
125-
126- public void Finally (object message , Exception ? exception , CancellationToken cancellationToken )
127- {
128- if (exception != null )
114+ if (! TryValidate (message , out var errors ))
129115 {
130- Console .WriteLine ($" 🌍 Error: {exception .Message }" );
116+ // If validation fails, short-circuit the handler execution
117+ return HandlerResult .ShortCircuit (Result .Invalid (errors ));
131118 }
119+
120+ return HandlerResult .Continue ();
132121 }
133122}
123+
124+ var user = mediator .InvokeAsync <Result <User >>(new GetUserQuery (userId ), cancellationToken );
134125```
135126
136127## 💉 Dependency Injection Made Simple
@@ -274,12 +265,11 @@ dotnet run
274265
275266The source generator:
276267
277- 1 . ** Discovers handlers** at compile time by scanning for classes ending with "Handler" or "Consumer"
278- 2 . ** Validates method signatures** to ensure they follow the conventions
268+ 1 . ** Discovers handlers** at compile time by scanning for classes ending with ` Handler ` or ` Consumer `
269+ 2 . ** Discovers handler methods** looks for methods with names like ` Handle ` , ` HandleAsync ` , ` Consume ` , ` ConsumeAsync `
270+ 3 . ** Parameters** first parameter is the message, remaining parameters are injected via DI
2792713 . ** Generates C# interceptors** for blazing fast same-assembly dispatch using direct method calls
280- 4 . ** Registers keyed handlers in DI** as fallback for cross-assembly scenarios and publish operations
281- 5 . ** Creates middleware pipelines** with proper before/after/finally execution order
282- 6 . ** Generates handler registrations** that span multiple projects for comprehensive handler discovery
272+ 4 . ** Middleware** with can run ` Before ` , ` After ` , and ` Finally ` around handler execution and can be sync or async
283273
284274### 🔧 C# Interceptors - The Secret Sauce
285275
0 commit comments