© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•14mo ago•
27 replies
BoomSonK

Reuse handlers with MediatR?

Hi,
I would like to know the best approach to share the same code in a codebase with CQRS and MediatR. Suggest a simple CRUD. You have a GetById, but also an Update and Delete. For the Update and Delete handlers I also have to retrieve the entity first, but they use the same logic as the GetById handler. Now I was wondering what the best approach is to do this with principles in mind, such as DRY, SRP and the fact that you don't want to have too many dependencies to keep it modular. In short, is it common to call the Update and Delete handler into the GetById handler, or re-implement the GetById logic in the Update and Delete handler, or should I create an additional service where all those handlers get this logic from. The last option seems best to me, I think.

I'd love to hear from you!
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ How explicitly define command and handlers for MediatR
C#CC# / help
3y ago
CQRS With no Mediatr
C#CC# / help
15mo ago
Simple Injector with mediatR
C#CC# / help
2y ago
Implementing MediatR
C#CC# / help
3y ago