Passing arguments to next in pipeline behaviors
See original GitHub issueCurrently, the next
parameter in IPipelineBehavior<TRequest, TResponse>.Handle
is a RequestHandlerDelegate<TResponse>
which takes no argument.
This is a problem, because it means it’s impossible for a behavior to pass anything other than the original request to the next behavior.
Here are two examples where it could be useful to be able to do that:
- Applying a transformation to the request before it’s passed to the rest of the pipeline. It’s possible to modify the current one, but that works only if the request is mutable.
- Passing a different cancellation token. For instance, I’d like to pass
HttpContext.RequestAborted
if no cancellation token was passed explicitly.
I realize this would be a breaking change, but maybe in a future major version?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:11
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Manipulate pipeline with behaviors • NServiceBus
At runtime, the pipeline will call the Invoke method of each registered behavior passing in as arguments the current message context and an ......
Read more >Feature spotlight: Passing parameters between actions | Buddy
The 'Pass arguments' action in Buddy lets you ask about parameters during pipeline execution.
Read more >Advanced features of the MediatR package - Pipeline ...
Each of the pipeline behaviors can implement a single cross-cutting ... and their Handle method has an extra delegate parameter called next.
Read more >Pipeline execution and triggers - Azure Data Factory & ...
Pipeline runs are typically instantiated by passing arguments to parameters that you define in the pipeline. You can execute a pipeline ...
Read more >Pipeline parameters and variables - Azure Data Factory & ...
Pipeline parameters can be used to control the behavior of a pipeline and its activities, such as by passing in the connection details...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
yeah this is what I was thinking but I can see how it would get cumbersome.
This has been discussed before in a few other issues as well I think, here is one with a response from the author https://github.com/jbogard/MediatR/issues/361
A mutable dependency on both the pipeline(s) and the handler seems to be the suggested approach.
Hi @lilasquared,
How would you do that? The interface has to change anyway.
RequestHandlerDelegate<TResponse>
would need an additionalTRequest
generic type parameter, so it would no longer be the same type, so existing implementations would be broken.Of course, you could introduce a new interface for behaviors, but it would probably make things confusing…
Yes, that. My requests are often immutable.
Yes, I thought of doing this too. It’s not a big deal, but I thought a behavior would be a really good fit for this, so I was a little disappointed when I realized it wasn’t possible.
Yes, I’m aware of this limitation.