Sponsor: Interested in learning more about Distributed Systems Design? Enter for a chance to win a 5 day Advanced Distributed Systems Design course led by Udi Dahan founder of Particular Software, and creator of NServiceBus.
You’ve run into it. MediatR throwing an InvalidOperationException when you didn’t have a matching handler for a request. There’s a fairly simple solution to prevent this: Find MediatR Requests without Handlers.
So here’s some quick code you can throw in a unit test to verify you don’t have any missing handlers.
Find MediatR Requests without Handlers
The above code uses reflection to get all theIRequest<>, RequestHandler<> and RequestHandler<,>. Also worth mentioning it leverages Autofac for the IsClosedTypeOf method in the linq query.