Handler not found
See original GitHub issueI’m trying to register a generic request handler for a generic request, but I’m getting the error below when calling
await _mediator.Send(new ExchangeOrderRequest<ExchangeOrderResponseSuccessEvent>());
System.InvalidOperationException: Handler was not found for request of type MediatR.IRequestHandler2[MyNamespace.ExchangeOrderRequest
1[MyNamespace.ExchangeOrderResponseSuccessEvent],MediatR.Unit]. Register your handlers with the container. See the samples in GitHub for examples.
As side note, for giggles, I was able to inject an instance of IRequestHandler<ExchangeOrderRequest< ExchangeOrderResponseSuccessEvent>> into a controller just fine.
// Some assembly scanning, doesn't find my handler
services.AddMediatR(typeof(Startup), typeof(ExchangeOrderRequest), typeof(IDocumentMessage), typeof(OrderExecution.Handler));
// Try to manually add the handler. Still doesn't find it
services.AddTransient<IRequestHandler<ExchangeOrderRequest<ExchangeOrderResponseSuccessEvent>>, ExchargeOrderRequestHandler<ExchangeOrderResponseSuccessEvent, ExchangeOrderRequest<ExchangeOrderResponseSuccessEvent>>>();
public class ExchargeOrderRequestHandler<TEvent, TRequest> : IRequestHandler<TRequest>
where TRequest : ExchangeOrderRequest<TEvent>
where TEvent : ExchangeOrderEvent
{
// Stuff
}`
public class ExchangeOrderRequest<T>: DocumentMessage, IRequest where T: ExchangeOrderEvent
{
// Stuff
}
public class ExchangeOrderEvent : IEvent
{
// Stuff
}
What am I missing here?
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Handler not found - python
I recently made a code in python3.x and for the interface I used a .glade file but when I run the code the...
Read more >handler not found in main.py {lambda function }
You need to provide a dedicated handler there, import main.py and initialize Mangum. Let's prepare handler = Mangum (app,) separately. Please refer to...
Read more >NotFound Handler for ASP.NET Core and Optimizely
The NotFound handler stores the redirects in the database. Editors can add redirects without any deployments. All redirects are edited in the Admin...
Read more >Ansible - Handler not found on first attempt
I just found out the hard way. handlers only works with include_tasks not import_tasks . The error message is rather missdirecting. I went...
Read more >Not Found Handler - mezzio-problem-details - Laminas Docs
This library provides a Not Found handler so that returned 404 responses are in the problem details format. This handler will create a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Use a different container, the Microsoft DI container often can’t handle these edge cases, and this is one of them. It can’t handle partially closed generic types.
Otherwise, it might be fixed in the registration side of things, we might be able to forward registrations perhaps?
I use Ninject in a .Net 4.8 project and IRequestHandler<,> can’t be resolved through the ContravariantBindingResolver based on MediatR.Examples.Ninject. Could it also be the container in fault?