BookARoom is a simple project to explain CQRS during a live coding session at MS experiences'16 (slides are available here: https://github.com/tpierrain/CQRS-slides) or here on slideshare
The project is a dotnet core ASP.NET web site (in order to be containerized in the next session), allowing users:
- To consult and search for available rooms (READ model)
- To book a room (WRITE model)
Of course, booking a room (write model) will impact the read model accordingly.
This project is not a real one nor a prod-ready code. The intent here is to illustrate the CQRS pattern during a 40 minutes session. Thus, some trade-offs have been taken in that direction (e.g. the usage of Command and Queries terminology instead of domain specific names that I would have used otherwise).
CQRS without Event Sourcing?!?
Yes, since the timing will be short for this MS experiences'16 session in Paris (no more than 30 minutes of live-coding), I've decided to focus only on CQRS pattern, WITHOUT Event Sourcing (ES). Indeed, ES is often a mental dam for people's understanding. I also find important that people understand that CQRS Event sourcing, but CQRS != Event sourcing.
Highlights of the talk
-
CQRS (WITHOUT Event Sourcing):
- Why CQRS?
- Pattern origin
- How read and write models articulate
- Eventual consistency challenges and options
- Short clarification between CQRS & Event sourcing
-
How Outside-in TDD works
-
How Hexagonal Architecture can help us to focus on Domain first, before tackling the infra code (ASP.NET) in a second time
-
What is dotnet core and how it articulates with the new version of ASP.NET
Projects & Dependencies
-
BookARoom.Domain: containing all the domain logic of the solution (for both read and write models). (has no dependency)
-
BookARoom.Infra: containing the reusable infrastructure code (i.e. non-domain one like adapters, command handler, repositories) for both read and write models. (depends on both Domain and IntegrationModel projects)
-
BookARoom.Infra.Web: ASP.NET core project hosting the web infrastructure code (like ViewModels, Views and Controllers) which relies on the BookARoom.Infra code. (depends on both Domain, Infra and IntegrationModel projects)
-
BookARoom.Tests: containing tests for all projects. (depends on all the other BookARoom projects)
-
BookARoom.IntegrationModel: command-line project to generate integration json files for hotel (from code). (has no dependency)
Tips and tricks
How to run the tests
Note: resharper and ncrunch don't support yet dotnet core; you can only run them via Visual Studio test runner (e.g. Ctrl-R, A) or by executing:
dotnet test
within the BookARoom.Tests project directory.
CQRS in a nutshell
There are many forms of CQRS implementation. The implementation of the BookARoom project follows this version:
from original source: https://msdn.microsoft.com/en-us/library/jj591573.aspx
The objective of this lab is to add the "cancel a reservation" feature.
Step by step Instructions (following outside-in TDD technique) are presented here.
Tracks of improvement
- Fight against the current anemic model (mainly because I never worked on that topic and that I don't have any expert available to help me ;-( and embrace more the ubiquitous language of this domain.
...