I am working on a ASP.NET Core 2.2 Web API application with Mediatr.
I have a handler that looks like -
public class MyQueryHandler<T> : IRequestHanlder<MyQuery<T>, IQueryable<T>>
{
public Task<IQueryable<T>> Handle(MyQuery<T> myquery, CancellationToken cancellationToken)
{
//perform query
IQueryable<T> models = someDatabaseQuery.ProjectTo<T>();
}
}
This is the query -
public class MyQuery<T> : IRequest<IQueryable<T>>
{
//some properties
}
When I try to make a request like this -
var result = await _mediator.Send(new MyQuery<SomeModel> {/* set the properties on the query */})
I get an exception -
An unhandled exception occurred while processing the request.
InvalidOperationException: Handler was not found for request of type MediatR.IRequestHandler`2[MyQuery`1[SomeModel],System.Linq.IQueryable`1[SomeModel]]. Register your handlers with the container. See the samples in GitHub for examples.
I have spent quite a few hours tried a many things but none have worked. I even tired using Autofac along side the service collection, following the example provided in the Mediator github repo.