Andrew Rea - A Developer On A Few Platforms

C#, JAVA, ASP.NET, C++, ACTION SCRIPT

A rough mapping of a CQRS Implementation through a Sequence Diagram

Posted in .NET, Agatha, C#, CQRS by Andrew Rea on 7/11/2010 9:58:06 AM - CST

So I am currently looking at an example application implementing CQRS by Mark Nijhof.  You can find and check out the example application at github, http://github.com/MarkNijhof/Fohjin

This for me is a real example of where reading code improves your own outlook and skills in coding.  I feel this application is a superb example of good Architecture and encapsulates all the correct principles and practices which are encouraged and implemented through out the industry.    To try and understand how it all fitted together I thought I would just jump in and create a rough sequence diagram.  I used some excellent free software to create the diagram called Violet Uml Editor.

Please click to see a larger version.

FullCqrsMapping

In a previous post I mistakenly used the word event when I actually should have written command.  After studying the code base to construct the above diagram I can now make the following assumptions about it and in turn try to describe the work flow.

  1. On Application Start
    1. All Commands and CommandHandlers are resolved and added to the MessageRouter
    2. All Events and EventHandlers are resolved and added to the MessageRouter
  2. Client creates and publishes a command to the Bus
  3. The message router loops through all the command handlers and invokes each wrapped inside a Transaction handler.
  4. The Transaction Handler gets or adds the DomainObject through the DomainRepository which indirectly gets Registered For Tracking inside the UnitOfWork.
  5. When the Command Handler is executed, it is done so inside a wrapper.  This also invokes the Commit method on the UnitOfWork.
  6. The UnitOfWork will then loop through each of the Domain Objects (Event Providers) it has Registered For Tracking and do the following:
    1. Save the Domain Object (Event Provider) through the Domain Event Storage.
    2. Publish the events which have occurred for said Domain Object to the Bus
    3. The Domain Objects which are Registered For Tracking are then cleared.
  7. When the Events are published to the Bus, the Message Router will now loop through the EventHandlers it has for each event and invoke each.
  8. The Event Handlers will then interact with the Reporting Repository and update the Reporting Data Store accordingly.

This is not exact by any means as you will probably pick up on immediately, but I am gradually getting my head around what is happening with this application and CQRS in general, and liking more and ore as I go :) .

With the above in mind and the fact that I want to introduce the Service Layer using Agatha, I am thinking that the RequestHandlers in Agatha will have either of the following two responsibilities:

  1. Create a publish a Command to the Bus
  2. Interact with the Reporting Repository.

1.) Will deal with all the write requests obviously and 2.) with the read ones.  Once this is done, I can see a nice layer where the client is shielded from the CQRS and literally just executes Requests as normal.

Cheers for now,

Andrew

Comments

None.

Add Comment

Login using
Google Yahoo flickr AOL
and more
Or provide your details
Please enter your name. Please enter a valid email. Please enter a valid website.
Please supply a comment.
© Copyright 2010 Powered by AtomSite 1.4.0.0