jbogard / MediatR.Extensions.Microsoft.DependencyInjection

MediatR extensions for Microsoft.Extensions.DependencyInjection
MIT License
327 stars 90 forks source link

Do I need to register IPipelineBehaviors manually, or can this package handle it? #28

Closed tomasaschan closed 6 years ago

tomasaschan commented 6 years ago

I have a class FooBehavior implemented as follows:

public class FooBehavior : IPipelineBehavior<FooCommand, string>
    {
        public Task<string> Handle(FooCommand request, CancellationToken cancellationToken, RequestHandlerDelegate<string> next)
        {
            throw new NotImplementedException();
        }
    }

and I'm registering MediatR with just services.AddMediatR(typeof(FooHandler)) (where FooHandler and FooBehavior live in the same assembly). When running the application and sending a FooCommand, I don't see the behavior at all - I was expecting the application to throw, but it just keeps going as if nothing happened.

I think the problem might be these lines:

https://github.com/jbogard/MediatR.Extensions.Microsoft.DependencyInjection/blob/886b54b1301cbfb3decc71ee0e139398f400aab1/src/MediatR.Extensions.Microsoft.DependencyInjection/ServiceCollectionExtensions.cs#L91-L95

Should IPipelineBehavior<,> be among those interfaces? If not, what's the rationale behind leaving it out?

If you want it there, I can file a PR for the fix :)

jbogard commented 6 years ago

Yep, you do! Because they're ordered you have to register in the order you want. Pre-processors, the idea, do not have any order.