Unable to resolve service for type 'System.Object' while attempting to activate 'MediatR.ServiceFactory'
See original GitHub issueHi,
I’m upgrading my web app from ASP.NET Core 2.0 to ASP.NET Core 3.1. Also, I upgraded to Mediatr 8.0.1 and Mediatr.Extensions.Microsoft.DependencyInjection 8.0.0.
On startup, this exception is thrown:
Some services are not able to be constructed (Error while validating the service descriptor ‘ServiceType: System.ICloneable Lifetime: Transient ImplementationType: MediatR.ServiceFactory’: Unable to resolve service for type ‘System.Object’ while attempting to activate ‘MediatR.ServiceFactory’.) (Error while validating the service descriptor ‘ServiceType: System.Runtime.Serialization.ISerializable Lifetime: Transient ImplementationType: MediatR.ServiceFactory’: Unable to resolve service for type ‘System.Object’ while attempting to activate ‘MediatR.ServiceFactory’.)
I used to have this in Startup.cs to add Mediatr to dependency injection:
services.AddScoped<ServiceFactory>(p => p.GetService);
I also tried
services.AddMediatR(Assembly.GetExecutingAssembly());
but the exception still occurs.
Any idea why DI is not registering the ServiceFactory type correctly? How should I do this in ASP.NET Core 3.1? Downgrading again to Mediatr 7.0.0 didn’t help.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top GitHub Comments
Problem solved. I used to scan assemblies using the Scrutor package to register my Mediatr handlers.
Now I’m doing:
yes, I solved this problem. check all DI in the project, my problem in the UnitOfWork