Sponsor: Using RabbitMQ or Azure Service Bus in your .NET systems? Well, you could just use their SDKs and roll your own serialization, routing, outbox, retries, and telemetry. I mean, seriously, how hard could it be?

- 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 all aspects of this feature into one file. This single file contains our NancyFX Module and Route, Command and Command Handler.Validation
One small piece of validation I would like to add, is validating the CustomerId is not an empty Guid. When deserialization occurs thru the Bind() method, if the CustomerId is not present in the payload, the CustomerId will be an empty Guid (00000000-0000-0000-0000-000000000000). The simplest approach is to add the validation to our Handler. This doesn’t look incredibly horrible, however we are violating SRP and as you develop more complex commands, validating them will start to consume your Handler.Decorator Pattern
In object-oriented programming, the decorator pattern (also known as Wrapper, an alternative naming shared with the Adapter pattern) is a design pattern that allows behavior to be added to an individual object, either statically or dynamically, without affecting the behavior of other objects from the same class.[1] The decorator pattern is often useful for adhering to the Single Responsibility Principle, as it allows functionality to be divided between classes with unique areas of concern.[2]The decorator pattern is pretty straight forward, and even if you never knew the term, you likely already used it. Here is our decorator for wrapping the command handler with our new validation handler.