33using Foundatio . Mediator . Benchmarks . Handlers . Foundatio ;
44using Foundatio . Mediator . Benchmarks . Services ;
55using Microsoft . Extensions . DependencyInjection ;
6+ using Microsoft . Extensions . Hosting ;
7+ using Microsoft . Extensions . Logging ;
68using MassTransit ;
9+ using Wolverine ;
710
811namespace Foundatio . Mediator . Benchmarks ;
912
@@ -14,9 +17,11 @@ public class CoreBenchmarks
1417 private IServiceProvider _foundatioServices = null ! ;
1518 private IServiceProvider _mediatrServices = null ! ;
1619 private IServiceProvider _masstransitServices = null ! ;
20+ private IHost _wolverineHost = null ! ;
1721 private Foundatio . Mediator . IMediator _foundatioMediator = null ! ;
1822 private MediatR . IMediator _mediatrMediator = null ! ;
1923 private MassTransit . Mediator . IMediator _masstransitMediator = null ! ;
24+ private IMessageBus _wolverineBus = null ! ;
2025
2126 // Direct handler instances for baseline comparison
2227 private readonly FoundatioCommandHandler _directCommandHandler = new ( ) ;
@@ -65,6 +70,18 @@ public void Setup()
6570 } ) ;
6671 _masstransitServices = masstransitServices . BuildServiceProvider ( ) ;
6772 _masstransitMediator = _masstransitServices . GetRequiredService < MassTransit . Mediator . IMediator > ( ) ;
73+
74+ // Setup Wolverine
75+ _wolverineHost = Host . CreateDefaultBuilder ( )
76+ . ConfigureLogging ( logging => logging . ClearProviders ( ) )
77+ . UseWolverine ( opts =>
78+ {
79+ opts . Services . AddSingleton < IOrderService , OrderService > ( ) ;
80+ opts . Discovery . IncludeAssembly ( typeof ( CoreBenchmarks ) . Assembly ) ;
81+ } )
82+ . Build ( ) ;
83+ _wolverineHost . Start ( ) ;
84+ _wolverineBus = _wolverineHost . Services . GetRequiredService < IMessageBus > ( ) ;
6885 }
6986
7087 [ GlobalCleanup ]
@@ -77,6 +94,9 @@ public async Task Cleanup()
7794 await asyncDisposable . DisposeAsync ( ) ;
7895 else
7996 ( _masstransitServices as IDisposable ) ? . Dispose ( ) ;
97+
98+ await _wolverineHost . StopAsync ( ) ;
99+ _wolverineHost . Dispose ( ) ;
80100 }
81101
82102 // Baseline: Direct method calls (no mediator overhead)
@@ -123,6 +143,12 @@ public async Task MassTransit_Command()
123143 await _masstransitMediator . Send ( _pingCommand ) ;
124144 }
125145
146+ [ Benchmark ]
147+ public async Task Wolverine_Command ( )
148+ {
149+ await _wolverineBus . InvokeAsync ( _pingCommand ) ;
150+ }
151+
126152 // Scenario 2: InvokeAsync<T> (Query)
127153 [ Benchmark ]
128154 public async Task < Order > Foundatio_Query ( )
@@ -144,6 +170,12 @@ public async Task<Order> MassTransit_Query()
144170 return response . Message ;
145171 }
146172
173+ [ Benchmark ]
174+ public async Task < Order ? > Wolverine_Query ( )
175+ {
176+ return await _wolverineBus . InvokeAsync < Order > ( _getOrder ) ;
177+ }
178+
147179 // Scenario 3: PublishAsync with a single handler
148180 [ Benchmark ]
149181 public async Task Foundatio_Publish ( )
@@ -163,6 +195,12 @@ public async Task MassTransit_Publish()
163195 await _masstransitMediator . Publish ( _userRegisteredEvent ) ;
164196 }
165197
198+ [ Benchmark ]
199+ public async Task Wolverine_Publish ( )
200+ {
201+ await _wolverineBus . PublishAsync ( _userRegisteredEvent ) ;
202+ }
203+
166204 // Scenario 4: InvokeAsync<T> with DI (Query with dependency injection)
167205 [ Benchmark ]
168206 public async Task < Order > Foundatio_QueryWithDependencies ( )
@@ -183,4 +221,10 @@ public async Task<Order> MassTransit_QueryWithDependencies()
183221 var response = await client . GetResponse < Order > ( _getOrderWithDependencies ) ;
184222 return response . Message ;
185223 }
224+
225+ [ Benchmark ]
226+ public async Task < Order ? > Wolverine_QueryWithDependencies ( )
227+ {
228+ return await _wolverineBus . InvokeAsync < Order > ( _getOrderWithDependencies ) ;
229+ }
186230}
0 commit comments