Skip to content

MicroBus: In-Process Mediator

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.


I’ve blogged about the mediator pattern a lot.  Primarily because it’s been a good fit in several of the applications I’ve developed over the last few years.

Mediator Pattern

For those completely unfamiliar with the mediator pattern, here’s a brief summary:
With the mediator pattern, communication between objects is encapsulated with a mediator object. Objects no longer communicate directly with each other, but instead communicate through the mediator. This reduces the dependencies between communicating objects, thereby lowering the coupling.

Libraries

I’ve written my own implementations of the mediator library from project to project.  Once I finally found the MediatR library, I’ve pretty much been using it instead of my own. In a recent post about MediatR v3’s new Behaviors, Daniel Little commented about his implementation called MicroBus. I love checking out new libraries to see what’s out there.  I’ve gotten a lot of feedback about other OSS libraries and tools I’ve blogged about. I figured this was a good opportunity to mention library that look pretty interesting and may be worth taking a deeper look at.

MicroBus

This library actually looks more like what I’ve built myself in the past. The first thing to notice is there are two separate interfaces for defining a Command or a Query.
There isn’t anything surprising when you look at implement your handlers.  It’s pretty straight forward and what you would expect.  Familiar things are nice.

Cross Cutting Handlers

What’s really interesting is how it handles cross cutting concerns.  You can create global handlers via the IDelegatedHandler interface or create a pipeline with IPipeline interface.

BusBuilder

Another interesting aspect is how you build up registering your handlers.  There is built in support for Autofac

Comments

From the looks of it MicroBus looks like a pretty nice implementation of the mediator pattern with a lot of features people are looking for such as pipelines. Check it out on GitHub.  It is a very active project (as of this posting). If you want to see a real world demo, possibly of my MusicStore sample app but using MicroBus, please let me know! If you have another library you would like me to blog about feel please let me know in the comments or on Twitter.

Leave a Reply

Your email address will not be published. Required fields are marked *