Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/DispatchR/Configuration/ServiceRegistrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ public static void RegisterHandlers(IServiceCollection services, List<Type> 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())
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace DispatchR.TestCommon.Fixtures.Interfaces;

public interface INonGenericInterface;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Runtime.CompilerServices;
using DispatchR.Abstractions.Send;

namespace DispatchR.TestCommon.Fixtures.SendRequest.AsyncEnumerable;

public class AsyncEnumerableHandler : IRequestHandler<AsyncEnumerableRequest, IAsyncEnumerable<int>>
{
public async IAsyncEnumerable<int> 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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using DispatchR.Abstractions.Send;

namespace DispatchR.TestCommon.Fixtures.SendRequest.AsyncEnumerable;

public class AsyncEnumerableRequest : IRequest<AsyncEnumerableRequest, IAsyncEnumerable<int>>;
Original file line number Diff line number Diff line change
@@ -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<TRequest, TResponse>
: INonGenericInterface,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This interface was added here to achieve 100% code coverage when searching for a matching pipeline interface:

pipeline.GetInterfaces().First(inter =>
    inter.IsGenericType && // <=== This branch when `false`
    inter.GetGenericTypeDefinition() == behaviorType).GenericTypeArguments[1]

IPipelineBehavior<TRequest, IAsyncEnumerable<TResponse>>
where TRequest : class, IRequest<TRequest, IAsyncEnumerable<TResponse>>, new()
{
public required IRequestHandler<TRequest, IAsyncEnumerable<TResponse>> NextPipeline { get; set; }

public async IAsyncEnumerable<TResponse> Handle(TRequest request, [EnumeratorCancellation] CancellationToken cancellationToken)
{
await foreach (var item in NextPipeline.Handle(request, cancellationToken))
{
yield return item;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using DispatchR.Abstractions.Send;

namespace DispatchR.TestCommon.Fixtures.SendRequest;

public class GenericPipelineBehaviorTaskWithoutResponse<TRequest, TResponse>()
: IPipelineBehavior<TRequest, System.Threading.Tasks.Task>
where TRequest : class, IRequest<TRequest, System.Threading.Tasks.Task>, new()
{
public System.Threading.Tasks.Task Handle(TRequest request, CancellationToken cancellationToken)
{
return NextPipeline.Handle(request, cancellationToken);
}

public required IRequestHandler<TRequest, System.Threading.Tasks.Task> NextPipeline { get; set; }
}
Loading