Error constructing handler for request of type Mediat.RequestHandler 2. Issue with Autofac or Mediatr?

46 Views Asked by At

First of all, I am aware that this error is very generic and there exists many such posts with similar error on stack overflow but still I am unable to overcome this issue. First of all the strange situation is: This issue doesn't happen in my local system but when code is deployed to a container in QA environment then this following error starts occurring:

System.InvalidOperationException Error constructing handler for request of type Mediat.RequestHandler 2[Appl icationServices.ConnectToTargetEnvironment.ConnectToTargetEnvironmentCommand, ApplicationServices.ConnectToTargetEnvironment.ConnectToTargetEnvironmentResponse). Register your handlers with the container

We are using Autofac and Mediatr packages in our solution and I feel issue falls more towards Autofac after looking at the exception. The other strange scenario is this excpetion occurs only with the 'ConnectToTargetEnvironmentHandler' and other handlers work just fine in QA.

Project Structure

'GetTargetEnvironmentsHandler' works just fine in QA but the 'ConnectToTargetEnvironmentHandler' throws the above mentioned exception in QA.

I have tried the following things but that didn't yield me any positive results:

  1. builder.RegisterType<ConnectToTargetEnvironmentHandler>().As<IRequestHandler<ConnectToTargetEnvironmentCommand, ConnectToTargetEnvironmentResponse>>().InstancePerLifetimeScope(); where builder is ContainerBuilder type.
  2. services.AddMediatR(AppDomain.CurrentDomain.GetAssemblies()); services.AddMediatR(typeof(ConnectToTargetEnvironmentCommand).GetTypeInfo().Assembly); services.AddMediatR(typeof(ConnectToTargetEnvironmentResponse).GetTypeInfo().Assembly); where services is IServiceCollection contract.

What might be wrong or How can I fix this issue which is occurring just on QA??.

0

There are 0 best solutions below