Revise the request handler API
See original GitHub issueThe 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, butIRequestHandler
(without the word “async”) is also used for asynchronous handlers. - There is a unconventional
Unit
struct to representvoid
.
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:
- Created 4 years ago
- Comments:9 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
IRequestHandler<TRequest, TResponse>
IRequestHandler<TRequest>
INotificationHandler<TNotification>
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.