Category Archives for Backend

How To Validate Commands in a CQRS Application

Any of these sound familiar?

Rubbish in rubbish out.

Never trust user input.

If you’ve ever built any sort of professional application you will have had to validate user input. Whether it is to ensure a valid email address or something more complicated. There are tried and tested ‘rules’ for doing this safely while being nice the user.

  1. Validate on the client side – makes for a better user experience
  2. And validated on the server – never trust user input

But here’s a question..

If you issue commands rather than send in models, where should the validation occur?

The most obvious answer is in the domain model.

But this poses a problem…Continue reading

How to including static services in a testable way

There are often times when you want to include static services in your code. For example, when accessing the file system or including an external analytics package. When you do, it presents a testability problem. Every time you exercise the code via a test, that static service is also called. This post explains a simple pattern I use to solve this issue.Continue reading

‘Messaging’, the new silver bullet?

I had an ‘Ah ha!’ moment just over a year ago when I attended a Greg Young’s CQRS and Event sourcing course with skillsmatter. The ‘Ah ha’ wasn’t about CQRS, or even Event sourcing, it was about how Greg structured his code to work with messages. This approach can have far reaching effects on your software, making it simpler, easier to test and much more flexible. It can even remove the need for an AOP framework (amongst other things).Continue reading