diff --git a/src/DispatchR/Configuration/ServiceRegistrator.cs b/src/DispatchR/Configuration/ServiceRegistrator.cs index b716195..b57d506 100644 --- a/src/DispatchR/Configuration/ServiceRegistrator.cs +++ b/src/DispatchR/Configuration/ServiceRegistrator.cs @@ -125,6 +125,14 @@ public static void RegisterHandlers(IServiceCollection services, List allT continue; } + // If both are non-generic (Task vs ValueTask), then compare directly + if (!responseTypeArg.GenericTypeArguments.Any() && + !genericHandlerResponseType.GenericTypeArguments.Any() && + responseTypeArg != genericHandlerResponseType) + { + continue; // Task != ValueTask, so skip + } + // register async generic pipelines if (responseTypeArg.GenericTypeArguments.Any()) { diff --git a/tests/DispatchR.TestCommon/Fixtures/Interfaces/INonGenericInterface.cs b/tests/DispatchR.TestCommon/Fixtures/Interfaces/INonGenericInterface.cs new file mode 100644 index 0000000..f2b0e91 --- /dev/null +++ b/tests/DispatchR.TestCommon/Fixtures/Interfaces/INonGenericInterface.cs @@ -0,0 +1,3 @@ +namespace DispatchR.TestCommon.Fixtures.Interfaces; + +public interface INonGenericInterface; diff --git a/tests/DispatchR.TestCommon/Fixtures/SendRequest/AsyncEnumerable/AsyncEnumerableHandler.cs b/tests/DispatchR.TestCommon/Fixtures/SendRequest/AsyncEnumerable/AsyncEnumerableHandler.cs new file mode 100644 index 0000000..364d2a8 --- /dev/null +++ b/tests/DispatchR.TestCommon/Fixtures/SendRequest/AsyncEnumerable/AsyncEnumerableHandler.cs @@ -0,0 +1,14 @@ +using System.Runtime.CompilerServices; +using DispatchR.Abstractions.Send; + +namespace DispatchR.TestCommon.Fixtures.SendRequest.AsyncEnumerable; + +public class AsyncEnumerableHandler : IRequestHandler> +{ + public async IAsyncEnumerable Handle(AsyncEnumerableRequest request, [EnumeratorCancellation] CancellationToken cancellationToken) + { + yield return await System.Threading.Tasks.Task.FromResult(1); + yield return await System.Threading.Tasks.Task.FromResult(2); + yield return await System.Threading.Tasks.Task.FromResult(3); + } +} diff --git a/tests/DispatchR.TestCommon/Fixtures/SendRequest/AsyncEnumerable/AsyncEnumerableRequest.cs b/tests/DispatchR.TestCommon/Fixtures/SendRequest/AsyncEnumerable/AsyncEnumerableRequest.cs new file mode 100644 index 0000000..8a27588 --- /dev/null +++ b/tests/DispatchR.TestCommon/Fixtures/SendRequest/AsyncEnumerable/AsyncEnumerableRequest.cs @@ -0,0 +1,5 @@ +using DispatchR.Abstractions.Send; + +namespace DispatchR.TestCommon.Fixtures.SendRequest.AsyncEnumerable; + +public class AsyncEnumerableRequest : IRequest>; diff --git a/tests/DispatchR.TestCommon/Fixtures/SendRequest/AsyncEnumerablePipelineBehavior.cs b/tests/DispatchR.TestCommon/Fixtures/SendRequest/AsyncEnumerablePipelineBehavior.cs new file mode 100644 index 0000000..5135830 --- /dev/null +++ b/tests/DispatchR.TestCommon/Fixtures/SendRequest/AsyncEnumerablePipelineBehavior.cs @@ -0,0 +1,21 @@ +using System.Runtime.CompilerServices; +using DispatchR.Abstractions.Send; +using DispatchR.TestCommon.Fixtures.Interfaces; + +namespace DispatchR.TestCommon.Fixtures.SendRequest; + +public class AsyncEnumerablePipelineBehavior + : INonGenericInterface, + IPipelineBehavior> + where TRequest : class, IRequest>, new() +{ + public required IRequestHandler> NextPipeline { get; set; } + + public async IAsyncEnumerable Handle(TRequest request, [EnumeratorCancellation] CancellationToken cancellationToken) + { + await foreach (var item in NextPipeline.Handle(request, cancellationToken)) + { + yield return item; + } + } +} diff --git a/tests/DispatchR.TestCommon/Fixtures/SendRequest/GenericPipelineBehaviorTaskWithoutResponse.cs b/tests/DispatchR.TestCommon/Fixtures/SendRequest/GenericPipelineBehaviorTaskWithoutResponse.cs new file mode 100644 index 0000000..f7e1c32 --- /dev/null +++ b/tests/DispatchR.TestCommon/Fixtures/SendRequest/GenericPipelineBehaviorTaskWithoutResponse.cs @@ -0,0 +1,15 @@ +using DispatchR.Abstractions.Send; + +namespace DispatchR.TestCommon.Fixtures.SendRequest; + +public class GenericPipelineBehaviorTaskWithoutResponse() + : IPipelineBehavior + where TRequest : class, IRequest, new() +{ + public System.Threading.Tasks.Task Handle(TRequest request, CancellationToken cancellationToken) + { + return NextPipeline.Handle(request, cancellationToken); + } + + public required IRequestHandler NextPipeline { get; set; } +} \ No newline at end of file