Skip to content

Commit b801e95

Browse files
committed
Fix tests
1 parent d9748c6 commit b801e95

4 files changed

Lines changed: 6 additions & 9 deletions

File tree

src/Foundatio.Mediator.Abstractions/Mediator.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,7 @@ private PublishAsyncDelegate[] GetAllApplicableHandlers(object message)
194194
[DebuggerStepThrough]
195195
private IEnumerable<HandlerRegistration> GetHandlersForType(Type type)
196196
{
197-
var handlers = _serviceProvider.GetKeyedServices<HandlerRegistration>(MessageTypeKey.Get(type));
198-
if (handlers != null && handlers.Any()) return handlers;
199-
200-
return Array.Empty<HandlerRegistration>();
197+
return _serviceProvider.GetKeyedServices<HandlerRegistration>(MessageTypeKey.Get(type)).ToArray();
201198
}
202199

203200
private static readonly ConcurrentDictionary<Type, object> _middlewareCache = new();

src/Foundatio.Mediator.Abstractions/MediatorExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static IServiceCollection AddMediator(this IServiceCollection services, A
6565
/// <returns></returns>
6666
public static IServiceCollection AddHandler(this IServiceCollection services, HandlerRegistration registration)
6767
{
68-
services.AddKeyedSingleton<HandlerRegistration>(registration.MessageTypeName);
68+
services.AddKeyedSingleton(registration.MessageTypeName, registration);
6969
services.AddSingleton(registration);
7070
return services;
7171
}

tests/Foundatio.Mediator.Tests/BasicHandlerGenerationTests.GeneratesWrapperForSimpleHandler.verified.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ public static class Tests_MediatorHandlers
164164
// Register HandlerRegistration instances keyed by message type name
165165
// Optionally register handler classes into DI based on MediatorHandlerLifetime setting
166166

167-
services.AddKeyedSingleton<HandlerRegistration>(MessageTypeKey.Get(typeof(Ping)),
168-
new HandlerRegistration(
167+
services.AddHandler(new HandlerRegistration(
169168
MessageTypeKey.Get(typeof(Ping)),
169+
"PingHandler_Ping_Handler",
170170
PingHandler_Ping_Handler.UntypedHandleAsync,
171171
null,
172172
true));

tests/Foundatio.Mediator.Tests/DIRegistrationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public class BHandler { public void Handle(B m) { } }
1717

1818
var (_, _, trees) = RunGenerator(src, [ new MediatorGenerator() ]);
1919
var di = trees.First(t => t.HintName.EndsWith("_MediatorHandlers.g.cs"));
20-
Assert.Contains("AddKeyedSingleton<HandlerRegistration>(MessageTypeKey.Get(typeof(A))", di.Source);
21-
Assert.Contains("AddKeyedSingleton<HandlerRegistration>(MessageTypeKey.Get(typeof(B))", di.Source);
20+
Assert.Contains("MessageTypeKey.Get(typeof(A))", di.Source);
21+
Assert.Contains("MessageTypeKey.Get(typeof(B))", di.Source);
2222
Assert.Contains("UntypedHandleAsync", di.Source);
2323
Assert.Contains("UntypedHandle(", di.Source);
2424
}

0 commit comments

Comments
 (0)