SimpleMediator icon indicating copy to clipboard operation
SimpleMediator copied to clipboard

Add an endpoint that supports generics

Open dasiths opened this issue 6 years ago • 2 comments

This will be slightly faster than using reflection to figure out the request type.

But the calling signature has to be explicit in defining the <message,response>

     // without generics
       var result = await mediator.HandleAsync(simpleQuery, context);

     // with generics
      var result = await mediator.HandleAsync<SimpleQuery, SimpleResponse>(simpleQuery, context);

dasiths avatar Aug 14 '19 07:08 dasiths

I agree that specifying generic parameters explicitly is not good. Do you know what kind of constraints MediatR has in place so it magically works?

abatishchev avatar Aug 14 '19 16:08 abatishchev

I agree that specifying generic parameters explicitly is not good. Do you know what kind of constraints MediatR has in place so it magically works?

It doesn't use generics to define the TRequest like my first method. Hence doesn't require explicit specifying when called.

https://github.com/jbogard/MediatR/blob/master/src/MediatR/Mediator.cs

dasiths avatar Aug 15 '19 00:08 dasiths