4

How can I set the priority of PipelineBehaviors? I have 3 pipeline. I want to execute AuthorizationPipeline first. If the AuthorizationPipeline throws any SecurityException, I am not going to execute other pipelines.

Abdulkadir KG
  • 83
  • 1
  • 8

1 Answers1

4

From the github wiki of MediatR: "Just register the behaviors in the order you would like them to be called."

https://github.com/jbogard/MediatR/wiki/Behaviors#registering-pipeline-behaviors

spyros__
  • 1,311
  • 6
  • 8
  • In this situation, if I have multi layer and my pipelines are seperated, it is not make sense for me. For example my logging and validation pipelines are in ```Core``` layer and my transaction pipeline is ```Business``` layer. For example I want to execute transaction pipeline middle of them of all. How can I handle it when service registration extensions seperated between core and business layer? – Abdulkadir KG May 29 '22 at 21:26
  • 2
    what you want was in discussion here: https://github.com/jbogard/MediatR/pull/509 not sure you can control the order – spyros__ May 30 '22 at 03:19
  • 1
    You can always register all pipelines in a separate file. For example you could have all the pipelines in a project named shared and all your other layers could reference that one. – spyros__ May 30 '22 at 03:23
  • @AbdulkadirKG You could define your pipeline behavior classes in your respective projects and then register them all with the DI container in one place* in the sequence you want them to be called, keeping in mind DI container-specific ordering controls noted on the MediatR PR link previously posted by spyros__. *The "one place" is your application composition root (https://blog.ploeh.dk/2011/07/28/CompositionRoot/). – Jonathan Lundquist Aug 11 '22 at 08:57