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.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 PatternFor 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.
LibrariesI’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.
MicroBusThis 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 HandlersWhat’s really interesting is how it handles cross cutting concerns. You can create global handlers via the
IDelegatedHandlerinterface or create a pipeline with