How to Command Query Responsibility Segregation (CQRS) with ASP.NET MVC?

Jeff picture Jeff · Mar 8, 2010 · Viewed 10.1k times · Source

I have been reading about Command Query Responsibility Segregation (CQRS). I sort of wonder how would this work with ASP.NET MVC? I get the idea of CQRS conceptually it sounds nice and sure does introduce some complexities (event and messaging pattern) compared to the "normal/common" approach . Also the idea of CQRS sort of against the use of ORM in some ways. I am trying to think how I could use this pattern in the coming projects so if anyone has experience in combining CQRS with ASP.NET MVC and NHibernate please give some concrete examples to help me better understand CQRS and use with ASP.NET MVC. Thanks!

Updated: I've been going through Mark's sample code. It's a must read if you are learning CQRS.

http://github.com/MarkNijhof/Fohjin

http://cre8ivethought.com/blog/2009/11/12/cqrs--la-greg-young/

http://cre8ivethought.com/blog/2009/11/28/cqrs-trying-to-make-it-re-usable/

Answer

Szymon Pobiega picture Szymon Pobiega · Mar 8, 2010

Please take a look at my DDDsample.Net project on CodePlex. The GUI is implemented using ASP.NET MVC while the business logic using DDD practices in 4 different variants:

  • classic (no CQRS)
  • CQRS with two NHIbernate relational data stores
  • CQRS with LINQ to SQL on reporting side
  • CQRS with Event Sourcing on command side