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.

Revise the request handler API

See original GitHub issue

The current API is confusing.

  • For some request handlers you implement an interface, for other request handlers you inherit from an abstract base class.
  • The AsyncRequestHandler (with the word “async”) is used for asynchronous handlers, but IRequestHandler (without the word “async”) is also used for asynchronous handlers.
  • There is a unconventional Unit struct to represent void.

Current API

The current API uses a mix of both interfaces and abstract base classes.

Description Type Name
Asyncronous with response Interface IRequestHandler<TRequest, TResponse>
Asyncronous without response Abstract AsyncRequestHandler<TRequest>
Syncronous Abstract RequestHandler<TRequest, TResponse>

Uhm, this is confusing and I am probably wrong here about something.

Proposal

Description Type Name
Asyncronous with response Interface IAsyncRequestHandler<TRequest, TResponse>
Asyncronous without response Interface IAsyncRequestHandler<TRequest>
Syncronous with response Interface IRequestHandler<TRequest, TResponse>
Syncronous without response Interface IRequestHandler<TRequest>
  • Unify usage by always and consistently using interfaces for both sync and async, as well as for both with and without response.
  • Drop the abstract base classes.
  • Drop the Unit struct.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
lilasquaredcommented, Nov 13, 2019

The move to a single interface (async first) was an explicit move for MediatR v4.0 - you can check out the release notes here https://github.com/jbogard/MediatR/releases/tag/v4.0.1

I agree with @khellang that the classes are simply convenience classes and are not part of public API / Interface of the library, they are simply implementations of the interface to reduce boilerplate code on the users part. Use them, or don’t. The public api for MediatR Handlers is simply

Description type Name
Asyncronous with response Interface IRequestHandler<TRequest, TResponse>
Asyncronous without response Interface IRequestHandler<TRequest>
Asyncronous without response Interface INotificationHandler<TNotification>
0reactions
vanillajonathancommented, Nov 13, 2019

Yes and no. As I said in my first comment; they’re convenience classes to save you from writing some cruft, like wrapping results in a Task if your handler is synchronous, or returning Unit if you don’t care about the result. That’s it.

Well wrapping the result in a Task is rather simple, and I would say its easier than to figure out which of all those base classes to use. As for when not caring about the result, isn’t there the IRequestHandler<TRequest> interface for that?

I feel these base classes cause more confusion than convenience.

Read more comments on GitHub >

github_iconTop Results From Across the Web

resetHandlers() - Api - Mock Service Worker Docs
Removes any request handlers that were added on runtime (after the initial setupServer call). This function accepts an optional list of request ......
Read more >
How to handle revisions and subresources in an HTTP ...
I'm in the process of designing a RESTful HTTP API for discussions. Each discussion consists of metadata and a collection of comments.
Read more >
Developing request handlers
This document explains how to implement and deploy a custom request handler. In most cases, implementing your own request handlers is unnecessary, ...
Read more >
Config API | Apache Solr Reference Guide 8.3
To update a request handler, you should use the update-requesthandler command: ... As a second example, we'll create another request handler, this time...
Read more >
HTTPRequestHandler API - OutSystems 11 Documentation
Provides actions to manipulate HTTP Requests and Responses. - OutSystems 11 Documentation.
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