Search code examples
.net-6.0.net-core-3.1mediatr

How to inject/Register MediatR ServiceFactory in .Net 6?


I have a project that originally written in .Netcore 3.1. I was migrating this project to .Net6.0.

I used to inject/Register the MediatR ServiceFactory with Lifetime: Transient.

services.AddTransient<ServiceFactory, ServiceFactory>();

But when I migrated to .Net6.0 I've got an error saying:

InvalidOperationException: Error while validating the service descriptor 'ServiceType: MediatR.ServiceFactory Lifetime: Transient ImplementationType: MediatR.ServiceFactory': Unable to resolve service for type 'System.Object' while attempting to activate 'MediatR.ServiceFactory'.

I would like to know how can I inject/Register the MediatR ServiceFactory in .Net6.0?


Solution

  • we shouldn't need to register the MediatR service factory as a separate thing. The AddMediatR extension should handle that.