Announcing Lokad.CQRS vLean - SampleProject and Tools
Thursday, January 5, 2012 at 22:49 Tweet in
Azure,
C#,
CQRS,
Cloud Computing,
DDD,
Event Sourcing,
Lokad,
xLim I've just finished assembling pre-release of Lokad.CQRS vLean (lean branch in github repository). From of this version Lokad.CQRS is no longer a framework, it is a full sample.
As such, Lokad.CQRS could be used for learning about event centric development (CQRS/DDD with event sourcing and ability to deploy in cloud and on-premises). Gradually growing series of articles in my bliki could provide some theoretical background.
You can also use Lokad.CQRS to jumpstart new projects by copying the entire SampleProject to your system and then modifying it to your needs. That's essentially how we start new projects at Lokad these days.
Because of this transition from "Framework" to "Sample with Sources" (aka "Reference Implementation"), I was finally able to include a lot of new material into this branch.
Sample Project
I've ripped part of domain code (simple account+users setup) from one of our projects, along with all the accompanying tooling, tests and engine. Current approach to event sourcing is also included (as explained in the bliki)
The project currently does not include:
- Deployment runners for Azure.Cloud (planned later, however Lokad.CQRS users should have pretty good sense of reconfiguring the domain to run in Azure).
- Web UI (but I might add it later, if time permits, since Razor + Bootstrap make really pleasant and fast development with this architecture).
I'll try to add these later (community contributions are also awesome).
Absence of Web UI makes it harder to visualize what's going inside. However you can still run tests and also start Sample.Engine (configured with file-based persistence and queues), that will fire a few commands, which will produce events that will be wired to sagas and projections. Just like in the real world.
Plus, this project includes some sample code and tools that are wired to it. These are used exactly how we currently use them (although not necessary how we will use them a few months later). Read below for more info.
Contracts DSL
Lokad Contracts DSL is an optional console utility that you can run in the background. It tracks changes to files with special compact syntax (as mentioned in commands and events on bliki) and updates CS file. Changes are immediate upon saving file (and ReSharper immediately picks them). This is an improved version of Lokad Code DSL, it supports identities and can auto-generate interfaces for aggregates and aggregate state classes.
You can try this out by starting SampleProject\Tools\Dsl project and then doing some changes to SampleProject\Domain\Sample.Contracts\Messages.tt.
Current DSL code generates contracts classes that are compatible with DataContracts, ServiceStack.JSON and ProtoBuf. Here are how they look like:
[DataContract(Namespace = "Sample")]
public partial class AddSecurityPassword : ICommand<SecurityId>
{
[DataMember(Order = 1)] public SecurityId Id { get; private set; }
[DataMember(Order = 2)] public string DisplayName { get; private set; }
[DataMember(Order = 3)] public string Login { get; private set; }
[DataMember(Order = 4)] public string Password { get; private set; }
AddSecurityPassword () {}
public AddSecurityPassword (SecurityId id, string displayName, string login, string password)
{
Id = id;
DisplayName = displayName;
Login = login;
Password = password;
}
}
Audit Tool
After you have run Sample.Engine, try starting Audit and opening with it this file temp\sample-tapes\domain.tmd (located in folder where the engine run). You should see something like this:

You'll probably figure out the purpose of color coding (or you could look out in the sources).
BTW, here's how the other tab looks like - it is used for automatically detecting and wiring all projections and then running the selected event stream through them:

Please keep in mind, that this is a fast rip from internal code, so a few buttons and functionality might not make full sense in the file-based context (i.e. domain log synchronization).
Simple Testing
I've been mentioning heavy abuse of Greg's SimpleTesting for dealing with specifications to test Aggregates. Source code for that is included (and for printing out them in readable format). Just fire your NUnit (either directly or via ReSharper):

This setup currently supports usual AR+ES testing, plus testing exceptions thrown by the domain code (domain errors), plus dealing with services and time.
Core Changes
There were a few core changes in the actual Lokad.CQRS framework. They were caused by the need to move forward and support wider range of scenarios (and better scalability). Actually, these features were mostly related to throwing things out - all builder syntax and containers. In the current version you wire everything without using overcomplicated builders. This leads to fewer dependencies and simpler code.
If you don't know, how old builder code translates to the new one - just check Wires and Engine projects in SampleProject (in addition to Snippets and unit tests for core building blocks).
In the spirit, we are gradually drifting away from style of architectures that is similar to NServiceBus, MassTransit and RhinoQueues (where you have handler classes plugged into the container for you). Instead, we are going directly for the type of architectures described by the outstanding ZMQ guide.
What's Next
As always, your feedback is always welcome (it helped to shape the current release and let us move forward). Please share it (along with any questions you might have) in Lokad community
A lot more is planned in this world along the following directions:
- Simplifying the core even further, along with solidifying the backing theory, based on real-world experience.
- Better support of multiple clouds (just Azure is not enough)
- Realt-time performance scenarios.
Stay tuned and participate in the community, if you are interested!
Reader Comments (9)
This is great!
Today I started toying around with the old Lokad.Cqrs. The FarleyFile project was the reason for me to have a closer look and eventually I decided to modify one of my projects to use this architecture.
During the process I of course had to dig deep into the inner guts of Lokad.Cqrs and it was especially hard to wrap my head around the configuration builders - they were really complicated - so I'm very glad that they are gone :)
Thanks for all your hard work! Ah new-code scent :))
Sebastian, Thank you for the encouraging feedback!
I'm really glad that the decision to discard builders and containers didn't go as bad as I was afraid of :)
Best,
Rinat
I have to agree with Sebastian. I can follow this project much easier. Great work. The Audit Tool and DSL are awesome.
BTW, for anyone wanting to use the sample project as a starting place, run Templify against the sample project directory and you can then easily deploy it with your own namespace and project name.
Deke, Thanks for the suggestion - that's the first time I've heard about Templify.
What's your experience of using it with sample project? Is there anything that could be improved in code to provide better experience?
You should post into a README within the project requirements, such as Windows Azure SDK Install Instructions: http://www.microsoft.com/download/en/details.aspx?id=28045
Another question: any plans on using Code Contracts and PEX to autogen your testing suite?
Mycall,
Thanks about reminder on Azure. I've added link to the homepage of Lokad.CQRS: http://lokad.github.com/lokad-cqrs/
Re CodeContracts and PEX: Code Contracts probably (if there are bugs discovered that need this functionality)
Best,
Rinat
Hi Rinat,
I am curious to see where ZMQ fits into your plans (timeline and architecture). I have started to use this amazing technology and would love for it to be integrated into your excellent work!
Regards,
Russ
@RUss,
Thanks for the compliments!
Latest Lokad.CQRS code is broken down to the point that it no longer stands in the way of using it with other technologies. Actually, there is a discussion at community ( https://groups.google.com/forum/#!topic/lokad/kD53JYzkV0o ) with Sebastian on ways to use ZMQ with Lokad.CQRS.
Personally I don't have any specific timeframes on publishing work on ZMQ - it will depend on how things work out at Lokad.