I'm using .Net Core 3.1
and MediatR
framework/library for query objects.
While executing the webApi\endpoint, I am getting the below issue
Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: MediatR.IRequestHandler
2[Queries.GetOrderResultQuery,System.Collections.Generic.IEnumerable
1[Models.Order.OrdersDto]] Lifetime: Transient ImplementationType: Queries.Handlers.GetOrderResultQueryHandler': Unable to resolve service for type 'Interfaces.Repositories.IOrderResultRepository' while attempting to activate 'Queries.Handlers.GetOrderResultQueryHandler'.)
This is my project Structure
GetOrderResultQueryHandler
services.AddMediatR
What I have tried I have tried the different options given in the net as below
//var mediatRTypes = new Type[] { typeof(AppCore.ServiceAppCore), typeof(Domain.OrderDomain) };
//services.AddMediatR(mediatRTypes);
services.AddMediatR(typeof(AppCore.ServiceAppCore),typeof(Domain.OrderDomain));//ServiceAppCore is a class in AppCore Project & OrderDomain is a class in Domain Project where I have Data Models
//services.AddMediatR(typeof(Startup)); // <===Gives Error Handler was not found for request of type MediatR.IRequestHandler`
//services.AddMediatR(AppDomain.CurrentDomain.GetAssemblies());
//services.AddMediatR(typeof(Startup).GetTypeInfo().Assembly);
//services.AddMediatR(Assembly.GetExecutingAssembly());// <===Gives Error Handler was not found for request of type MediatR.IRequestHandler`
For each of the options I get one or the other error mentioned below
I am new to this pattern and am not sure what I am missing here. Please suggest a resolution for this issue.
Check your Persistence project, you will see a RepositoryRegistration class in the Extensions folder. You should register your repository there like this:
public static void AddRepositories(this IServiceCollection services)
{
services.AddTransient<IYourRepositoryInterface, YourRepositoryClass>();
}