Skip to content

Commit 9e1e33a

Browse files
committed
fix: non-generic handler extending generic handler
1 parent d66b3e2 commit 9e1e33a

7 files changed

Lines changed: 20 additions & 28 deletions

File tree

src/Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project>
22

33
<PropertyGroup>
4-
<Version>1.0.0-alpha.22</Version>
5-
<PackageVersion>1.0.0-alpha.22</PackageVersion>
4+
<Version>1.0.0-alpha.23</Version>
5+
<PackageVersion>1.0.0-alpha.23</PackageVersion>
66
<Authors>Zapto</Authors>
77
<RepositoryUrl>https://github.com/zapto-dev/Mediator</RepositoryUrl>
88
<Copyright>Copyright © 2025 Zapto</Copyright>

src/Mediator.DependencyInjection/Generic/Handlers/GenericNotificationHandler.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ public async ValueTask<bool> Handle(IServiceProvider provider, TNotification not
102102
continue;
103103
}
104104

105-
var type = registration.HandlerType.MakeGenericType(arguments);
105+
var type = registration.HandlerType.IsGenericType
106+
? registration.HandlerType.MakeGenericType(arguments)
107+
: registration.HandlerType;
108+
106109
var handler = _serviceProvider.GetRequiredService(type);
107110

108111
await ((INotificationHandler<TNotification>)handler!).Handle(provider, notification, ct);

src/Mediator.DependencyInjection/Generic/Handlers/GenericRequestHandler.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ public async ValueTask<TResponse> Handle(IServiceProvider provider, TRequest req
9494
continue;
9595
}
9696

97-
var type = registration.HandlerType.MakeGenericType(arguments);
97+
var type = registration.HandlerType.IsGenericType
98+
? registration.HandlerType.MakeGenericType(arguments)
99+
: registration.HandlerType;
100+
98101
var handler = (IRequestHandler<TRequest, TResponse>) _serviceProvider.GetRequiredService(type);
99102

100103
_cache.RequestHandlerType = type;

src/Mediator.DependencyInjection/Generic/Handlers/GenericStreamRequestHandler.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ public IAsyncEnumerable<TResponse> Handle(IServiceProvider provider, TRequest re
8888
continue;
8989
}
9090

91-
var type = registration.HandlerType.MakeGenericType(arguments);
91+
var type = registration.HandlerType.IsGenericType
92+
? registration.HandlerType.MakeGenericType(arguments)
93+
: registration.HandlerType;
94+
9295
var handler = (IStreamRequestHandler<TRequest, TResponse>) _serviceProvider.GetRequiredService(type);
9396

9497
_cache.RequestHandlerType = type;

tests/Mediator.DependencyInjection.Tests/Generics/NotificationGenericTest.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public async Task Valid()
1919
{
2020
b.AddNotificationHandler(typeof(GenericNotificationHandler<>));
2121
b.AddNotificationHandler(typeof(GenericNotificationHandler<>));
22+
b.AddNotificationHandler<StringGenericNotificationHandler>();
2223
})
2324
.AddSingleton(result)
2425
.BuildServiceProvider();
@@ -27,14 +28,14 @@ await provider
2728
.GetRequiredService<IMediator>()
2829
.Publish(new GenericNotification<string?>(expected));
2930

30-
Assert.Equal(2, result.Values.Count);
31+
Assert.Equal(3, result.Values.Count);
3132
result.Values.Clear();
3233

3334
await provider
3435
.GetRequiredService<IMediator>()
3536
.Publish(new GenericNotification<string?>(null));
3637

37-
Assert.Equal(2, result.Values.Count);
38+
Assert.Equal(3, result.Values.Count);
3839
}
3940

4041
[Fact]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace Mediator.DependencyInjection.Tests.Generics;
2+
3+
public class StringGenericNotificationHandler(Result result) : GenericNotificationHandler<string>(result);

tests/Mediator.SourceGenerator.Tests/ServiceCollectionTests.GenerateEnumDefault#Request_Extensions.g.received.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)