How to specify which handler to route Mediator query/command?

13 Views Asked by At

I am exploring how to condense how I was taught the MediatR package's awesome infrastructure. I feel like this class:

    public class GetExamplesQuery : IRequest<GetExamplesResponse>
    {
        public GetExamplesQuery() { }
    }

Should be able to drive something like...

public class GetAllExamples : GetExamplesResponse { }

and then maybe without much trouble...

public class GetExamplesByIds : GetExamplesResponse { }

So... does that work?

Can you recommend a better pattern? It seems like a .Service layer should interpret the needs of .Api, and link it with the resources of .Data without every query having it's own trio of Query/Handler/Response classes. That's a hard sell to the department that's been free-balling for years.

Also, bless you if you just point me to an existing resource! Maybe I just want to blab about 2024 best practices.

0

There are 0 best solutions below