Skip to content

Sponsor: Do you build complex software systems? See how NServiceBus makes it easier to design, build, and manage software systems that use message queues to achieve loose coupling. Get started for free.

Learn more about Software Architecture & Design.
Join thousands of developers getting weekly updates to increase your understanding of software architecture and design concepts.


Follow @CodeOpinion

CQRS

Background Commands with MediatR and Hangfire

I’ve been using MediatR and Hangfire independently for awhile.  I’ve previously posted one solution on how you could use send Commands with MediatR and Hangfire. The solution I had come up with in that post was to get around the expression serialization issue with type parameters in MediatR’s Send<T>. IRequest<Unit> Because we are creating a a fire and forget command which will be run in the background, there will be no return value.  MediatR handles these types of requests by using the Unit type. When creating a command you will implement IRequest and your request handler will implement IRequestHandler<IRequest, Unit>.… Read More »Background Commands with MediatR and Hangfire

Mediator Pattern with Hangfire

I’ve run into situations where I need to perform actions requested by the client that may take a bit of time.  The length of time could be variable and I don’t want to have the client waiting for a response.  Let’s take a look at using the Mediator Pattern with Hangfire as a solution to this problem. In a Web API scenario, the request may come in as a PUT or POST from the client. The API would validate the request, send the task to a queue and then return the client a 202 HTTP status code. The request has been… Read More »Mediator Pattern with Hangfire

Validating Commands with the Decorator Pattern

This post is how I have manged to handle validating commands and queries and belongs to a series about different aspects of applying CQRS Although these examples are demonstrating usage in commands, they are aslo applicable to queries. Examples are using using MediatR to handle our requests. If you are unfamiliar with CQRS or MediatR, here are some other relevant posts: Organize by Feature Thin Controllers with CQRS and MediatR Query Objects instead of Repositories Mediator Pattern using MediatR and Unity Feature First let’s take a look at our feature for Changing a Customers Pricing Level.  In this example I’ve organized… Read More »Validating Commands with the Decorator Pattern