the program is not able to find handler for MediatR query ASP.Net Core
As I guessed, the problem was the Startup.cs where u add the MediatR service. Since my Handlers were in separate assembly so we should mention that assembly name. I changed this in Startup.cs
public void ConfigureServices(IServiceCollection services) {
services.AddMediatR(typeof(Startup));
}
To this:
public void ConfigureServices(IServiceCollection services){
var assembly = AppDomain.CurrentDomain.Load("Data");
services.AddMediatR(assembly);
}
Here "Data" is the name of my assembly where all Handlers are stored there.
I needed to use:
services.AddMediatR(typeof(DeletePeopleCommand).GetTypeInfo().Assembly);
You can use this
public void ConfigureServices(IServiceCollection services){
services.AddMediatR(AppDomain.CurrentDomain.GetAssemblies());
}
Here GetAssemblies()
will load all handler classes.