Home > Back-end >  MediatR Multiple Pipeline Behaviors
MediatR Multiple Pipeline Behaviors

Time:12-11

Helllo I already use this pattern of Mediator CQRS with Pipeline Behavior for a while, but just now i'm facing a issue where the generic implementation of TResponse and TRequest are not enough. So i'm trying to understand if having two separate pipelines for two very specific request is a bad practice or a bad ideia.

So the main idea is, having a PipelineBehavior<RequestOne, ResponseOne> to do a specific logic for the requestOne, and another PipelineBehavior<RequestTwo, ResponseTwo> to do another logic that doesn't apply to request one.

CodePudding user response:

I don't think its a bad idea at all, you can create an interface for mark all the requests you want to implement the PipelineX, and other for PipelineY.

Ex:
You have the RequestOne and RequestTwo classes that need to go through PipelineX, so you create and interface like IPipelineOne and mark the classes with it, then use reflection to process inside the pripeline middleware. The PipelineY will still run through these two classes and the rest of the program as well with no problems

  • Related