MediatR icon indicating copy to clipboard operation
MediatR copied to clipboard

Is it possible to access the innermost request handler from pipeline behavior?

Open nicholasyin opened this issue 3 years ago • 3 comments

For example, I'd like to do some conditional global handling based on the request handler. Has the handler instance been created and accessible at this moment?

nicholasyin avatar Sep 28 '21 01:09 nicholasyin

Hi @nicholasyin Could you please provide more details?

andrewtsw avatar Sep 28 '21 02:09 andrewtsw

I have a TransactionBehavior implementing the IPipelineBehavior interface and wrapping around all the inner behaviors and handlers. Its handler method is like this:

public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
{

}

So inside this method, is it possible to get access to the inside real request handler?

nicholasyin avatar Sep 28 '21 02:09 nicholasyin

I have a similar problem. I have different Behaviours, registered as generic pipeline behaviours. All of them are global. I want to use some of them for one group of handlers and the other for the second group of handlers. There is no ability to do this directly now. So, It could be a good ability to get the currently executed handler for, for example, an attribute or marker interface realization for the current handler to skip some of them.

RebelionTheGrey avatar Oct 03 '21 14:10 RebelionTheGrey