jbogard / MediatR

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

System.ArgumentException: "No assemblies found to scan. Supply at least one assembly to scan for handlers." #915

Closed DaveVdE closed 1 year ago

DaveVdE commented 1 year ago

Well this is awkward.

I want to use the official way of registering the Mediator service in the start up application, but since I'm using Autofac on top IServiceCollection, I'd rather register the different implementations of IRequestHandler<,> in the different Autofac modules spread across the solution.

Therefore, my Startup type only contains this:

services.AddMediatR(_ => {});

Only to be greeted with this helpful exception telling me I probably forgot to supply an assembly to scan. Perhaps there could be something added to prevent this? I mean other than having to add a dummy line that scans an assembly that has no request handlers?

jbogard commented 1 year ago

Look at the ServiceRegistrar class that exposes a method AddRequredServices to add the required services (i.e., none of the handlers). You'll then just not use AddMediatR.