question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scanning generics for mediatr handlers

See original GitHub issue

Hi. I have a generic mediatr request handler which looks like this:

  public class GetOneByIdHandler<T> : IRequestHandler<GetOneByIdRequest<T>, T> where T : IBaseEntity
    {
        private readonly IAsyncRepository<T> _asyncRepository;

        public GetOneByIdHandler(IAsyncRepository<T> asyncRepository)
        {
            _asyncRepository = asyncRepository;
        }

        public async Task<T> Handle(GetOneByIdRequest<T> request, CancellationToken cancellationToken)
        {
            return await _asyncRepository.GetOneByIdAsync(request.Id);
        }
    }

Right now I have to add the handler for every DTO manually. How can I automate this with Scrutor? Thanks!

services.AddTransient<IRequestHandler<GetOneByIdRequest<MyDto>, MyDto>, GetOneByIdHandler<MyDto>>();

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:17 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
alexb5dhcommented, Jan 6, 2021

@julealgon unfortunately my case is not related to MediatR only, but to custom services also, one of which is provided in the example.

0reactions
yuessircommented, Aug 27, 2022

any update? eg: ConcreteClass<T>:IConcrete<Foo< T >,T>

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - MediatR generic handlers
I use a MediatR library in my Asp .Net core 6 app. And I have a the same logic for a group of...
Read more >
How to register open-generic types (Command and ...
I'm building the app and trying to implement Domain Events with MediatR. I am on .NET Core 6 (preview, but I do not...
Read more >
You Probably Don't Need to Worry About MediatR
Actually, no, it's never used as a service locator. No one uses the IMediator interface to locate services. They use it to dispatch...
Read more >
MediatR and StructureMap–Using Generic ...
I ran into an issue after accidently enabling HSTS for a website on localhost. This was not an issue for the original website...
Read more >
CQRS and MediatR in ASP.NET Core
How to use the MediatR NuGet library in ASP.NET Core, and working with the CQRS and Mediator architectural patterns.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found