Open Mitchman215 opened 4 months ago
I have the same issue
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.
Not stale, this is still a problem as far as I am aware
Summary
It seems like
AddOpenBehavior
doesn't register the pipeline behaviorPipelineBehaviorImpl<TRequest, TNested>
whereTRequest : IRequest<SomeType<TNested>>
.Simple Example
Here is an example to demonstrate the issue when using generic lists:
Running the above code results in the following output:
This means the
ListGenericPipelineBehavior
was not run since the Before and After messages did not print.More complicated example
This issue also happens with other types beyond
List<T>
. My original use case was for pipelines that would apply to some abstract generic base class likeBaseCommand<T>
below:The only output from running the above example is
showing that
CommandPipelineBehavior
didn't run.Note: while testing this, I noticed that removing the
Result<T>
type entirely (ie making it soBaseCommand
implementsIRequest<TElement>
instead) resulted in the pipeline behavior being successfully called, so the problem seems to specifically be when the Request's return type has some nested generic parameter itself.Workaround
Explicitly registering the behaviors with
AddBehavior<ListGenericPipelineBehavior<ReturnListRequest, string>>()
andAddBehavior<CommandPipelineBehavior<StringCommand, string>>()
fixes the issue. This leads me to believe that the root of the problem is withAddOpenBehavior()
specifically and not in how the pipelines are looked up and run.Misc info
The above examples were using MediatR 12.3.0, Microsoft.Extensions.DependencyInjection 8.0.0, and targeting .NET 8 in a Windows environment.
If this is already a known limitation / feature that isn't meant to be implemented, then it'd be nice to document it in the Wiki