IRequestPreProcessor not called before IPipeLineBehavior
See original GitHub issueHi there,
I’m having some difficulties migrating my code to version 12.0.1.
I have a RequestPreProcessor defined as
public class RequestContextPreProcessor<TRequest> : IRequestPreProcessor<TRequest>
where TRequest : notnull, IHomeControllerRequest
and a number of Behaviors which I register using the follwoing code:
services.AddMediatR(config => {
config.RegisterServicesFromAssemblies(PluginProvider.GetAssemblies());
config.AddOpenBehavior(typeof(TelemetryBehavior<,>));
config.AddOpenBehavior(typeof(LoggingBehavior<,>));
config.AddOpenBehavior(typeof(ErrorHandlingBehavior<,>));
})
I can’t get the RequestPreProcessor to execute. For some reason, it’s not being registered and injected as part of the pipeline. My code worked fine with version 11. I tried explicitly registering the RequestPreProcessor, but that did not work either.
Any suggestions?
Thanks Alexander
Issue Analytics
- State:
- Created 7 months ago
- Reactions:1
- Comments:13 (2 by maintainers)
Top Results From Across the Web
.net - When should I use IPipelineBehavior over ...
They all get executed before the handler which is what I want them to do anyway. So my question is when would I...
Read more >Sharing Context in MediatR Pipelines
Basically, I'm recreating a lot of existing functional patterns in an OO language, using dependency injection. Side note - it's possible to do ......
Read more >How I Upgrade my Code-Style of MediatR Pipeline using . ...
I feel the MediatR attributes is missing the point of a behavior middleware, which is to handle common, cross-cutting concerns.
Read more >MediatR Behaviors
Looking at some of the new changes in MediatR v3. Including behaviors that enable you to create your own custom request pipelines.
Read more >Logging pipeline with MediatR
Before each request, all pipeline behaviours are called, if there are any, which wrap requests. This is what makes this blog post possible....
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
Hi @jbogard! Thanks for getting back and the explanations. Funny thing though is that I do have an
IRequestPreProcessor
implementation in the main assembly, but its Process() method does not get called (the class is being loaded though, because the constructor is called). The only way to get it to work is by manually adding the RequestPreProcessorBehavior<,> prior to any other custom behaviors.So this works:
Also, my code worked fine with v11.
I can live with manually adding the RequestPreProcessorBehavior, but it does seem strange and not how it’s supposed to work. So I did some more testing:
And as it turns out, my IRequestPreProcessor is being called, but in the wrong order. It gets called after my custom IPipeLineBehaviors, instead of before. I verified this by first removing all my custom behaviors and then by adding only a single custom beviour that does not depend on the IRequestPreProcessor, and then checking the call-order using breakpoints.
So it seems that the built in pipeline discovery is adding the behaviors in the wrong order, at least when configuring AddMediatR() the way I do it (see my first post please).
Hope this helps. Kind regards Alexander
I’m going to address this in the next release, to put request pre/post processors before behaviors.