I am open for suggestions to change for the better, do let me know your ideas in a comment. I had to delete all the Nuget files to keep the file size to the minimum, it will probably ask you to download these packages from Nu Get when you try to build it.Mvc With Cqrs (432 KB) I tried to ensure that the information posted here are up to date and accurate, however, I do not hold any responsibility to any damages that might occur from using or misusing the information and the posted code. There is no logging, there is no error handling, ofcourse, as this is not meant for production, it meant to be a sample, make it mainstream 🙂 The results?Controllers are nearly empty, DRY code and a pattern that is open for unit testing.Maybe we need a second-level dependency injector to decouple the first one.But, Ninject has a cool logo, so I don’t mind my modules depending on it 🙂 This is where the business logic lives.This is only the basic and the first building block in your CQRS application.You will probably add other CQRS related pattern on top of this.
This is the Please keep in mind, what we are doing here as a business logic is super simplistic and doesn’t show the true power of the CQRS pattern, but it does give you an idea.
Binding via Ninject (this code will apply to all my handlers, not just this one): I have used Mongo DB as a storage media, which you can Nu Get. I am using the following Ninject code to bind to it: I hope that I was able to illustrate the diagram above, feel free to ask me in a comment if I made a mistake or if you have a question.
Also, rather than implementing the popular Repository DDD pattern myself, one good chap implemented it for us for Mongo DB and packaged it as Nu Get, look at Nu Get for Mongo Repository. Let’s recap on the steps that the command of CQRS was implemented.
This is the plain CQRS with no other associated pattern. I could have chosen SQL Server, but for simplicity reasons and to get the idea across, Document DBs are easier to work with.
You could also tweak this sample implementation to work on an RDBMS as long as you get the repository right. NET MVC4, Mongo DB and Ninject to act as a starting template, in case you are going to use these technologies in your project with a CQRS pattern.