jbogard / MediatR

Simple, unambitious mediator implementation in .NET
Apache License 2.0
11k stars 1.16k forks source link

IRequestExceptionAction invocation issues #890

Closed nobugsincode closed 1 year ago

nobugsincode commented 1 year ago

I have a custom exception defined in my project public class CustomException : Exception. To log the exception I'm trying to use 2 approaches: one using IRequestExceptionAction<TRequest> and the second using IRequestExceptionAction<TRequest, TException>. MediatR registered in the service collection via services.AddMediatr(config => ...)

Problem

When I throw CustomException in one of my RequestHandlers I'm getting an invalid log lines in my console.

Expected behavior

I see a single log line for the exception thrown

Actual behavior

I see two log lines for same exception. Implementation of IRequestExceptionHandler<TRequest> not called at all.

Questions

Is it a bug or it's a desired behavior? I'm asking because multiple actions found here which looks quite intentional. But in this case what's the point of performing the same action multiple times? At the same time I don't see any registration for IRequestExceptionAction<TRequest> but only for IRequestExceptionAction<TRequest, TException> here. So what's the point to have any implementation of IRequestExceptionAction<TRequest>?

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

nobugsincode commented 1 year ago

Not stale yet :)

jbogard commented 1 year ago

I think the right thing to do here is to remove these extra interfaces. They can confuse the registration and resolution logic.