Posts tagged DDDSample
DDDSample.NET 0.5, finally asynchronous!
Dec 3rd
I am very proud to announce that just released version 0.5 of DDDSample.Net demonstrates (finally!) how inter-aggregate communication was supposed to work from the beginning: using asynchronous communication patterns.
Version 0.5 contains 3 different work modes (you can change them using solution configuration switch):
- InMemory. In this mode domain objects are not persisted but, instead, stored in static collections in main memory. This mode is intended to help novice users head-start with DDDSample since it does not need any additional configuration to work — just install the msi package.
- NHibernate. In this mode NHibernate is used to persist domain model data. Inter-aggregate communicaton is done synchronously using domain event pattern.
- NHibernateAsynch. This mode demonstrates full power of architectural approach used in DDDSample.Net. Data is stored using NHibernate while asynchronous communication between aggregates is handled by NServiceBus/MSMQ combination.
Next (minor) step in DDDSample.Net development should be probably replacing InMemory mode with SQLite in-memory database. What’s the difference? Current in-memory mode doesn’t use O/RM. It would be nice to have the sample as easy to run as it is now and have it persist it’s data using NHibernate so that users whould be able to see the process through all the layers.
DDDSample 0.4
Nov 16th
This release was meant to clean-up the CI stuff. Finally I managed to get scenario-based integration test ‘From Hongkong to Stockholm’ working correctly using SQLite both on TeamCity and localy.
There is also some increment with regard to functionality. I added ‘Next expected activity’ feature and modified main menu slightly. It now includes a page for listing all registered cargoes (helps greatly in testing).
Please, download from here and try if you like it!
DDDSample and Continous Integration
Nov 10th
Hi all!
I am proud to announce that DDDSample.Net finally has a Continous Integration configured. Big thanks to Kyle who accepted my registration request for a place on CodeBetter TeamCity server.
Direct effect of this event is the ‘Most recent builds’ area where you can track project progress. The indirect effect is that development work will be streamlined and finally there will be some hammer to hit me when I break the build.
Next thing to do is to create a WiX script to replace the Setup Project (setup projects require Visual Studio to be installed on the machine in order to generate the installation package).
In the meantime I will try to release the 0.4 version of DDDSample. Stay tuned!
DDDSample and Command-Query Separation
Nov 3rd
Command Query Separation is an architectural style which encourages building two separate models for one particular domain. One model is optimized for commands (modifications, like inserts, updates and deletes) and the other is optimized for queries (probably using star, warehouse-like schema).
The goals of CQS are to make both subsystems scale well using methods best suited for each one and to free the command model (which encapsulates the core business logic) from UI related code.
DDDSample is an implementation of sample from Eric Evans’ book and, as such, is not using CQS principles. It is that because its purpose is to demonstrate basics of DDD not ‘polluted’ by derived concepts.
Yet the DDD ‘knowledge crunching‘ process demonstrated in the book by Evans leads to a model which is very well suited for scaling. How is it done?
It is simply because DDDSample (as well as my .NET version) is built according to other good DDD practice–one which says that communication between aggregates is asynchronous. Despite not being named officially as CSQ-driven, DDDSample model has two aggregates representing the same concept (Cargo), one optimized for commands and the other one for queries.
Most of processing-intensive operations of Cargo entity are being done via Handling aggregate which asynchronously pushes notifications into the Cargo aggregate. The latter contains a lot of redundant information which is optimized for searching cargoes and displaying cargo information on the screen.
When I was thinking about future of DDDSample.Net I thought about CQS in the first place. After careful analysis I know it will not give any breakthrough in the field of scalability, but I hope it will make these scalability enabling aspects more explicit in the codebase and will clean up the core business code from presentation concerns.
Entities
Oct 28th
Entities are the stars of the domain model. They are the most valuable elements in terms of amount of business logic. They usually represent the most important real life concepts – those which have its own identity. And identity is something which is critical to the entities.
Entities which have different IDs are different entities. That is what the books would told you. But how does it look like in practice?
In DDDSample there is special interface for entities: IEntity. It defines one method
boolean sameIdentityAs(T other)
Implementation checks whether the other object is null (in this case returns false) and, if not, compares business identities of the objects.
There is also the equals method overridden on all entity classes. equals compares all the data contained in particular entity.
I think I understand some of the reasoning behind this solution. The sameIdentityAs method makes explicit that we are comparing business, not database, keys and that we care about identity. What I don’t understand is the equals method. Why on Earth should I compare entities by their value? Ideally (in CQS?) they should expose no values at all.
I decided to get rid of the equals (in my, C#, case Equals) overriding. That was the easy decision. Now the hard one: what to do with the SameIdentityAs? As you could read in the previous episode, I decided to get rid of similar method on value types. I think I had strong reasons there, but here?
The reason I consider giving up on the sameIdentityAs at all are ORMs. They provide me with an Identity Map out of the box – a warranty that two object references with same DB key are in fact one object instance on the heap. With that promise I can simply use == and != to compare addresses and the result is the same as business key comparison.
I strongly believe that all of my applications would use ORMs to store data in the foreseeable future. Even if I am wrong, in case I had to change my data access strategy completly, I wouldn’t expect that the change would be simply switching the DLLs. It certainly would be a painful task. I won’t make it easier just by pretending that I am not dependant on an ORM. Yes, I am and this fact is reflected clearly by the structure of the model. If I would plan to use OODBMS, I would structure my model completely different.
So, to sum up, we will get rid of those sameIdentityAs methods as well and use plain C# equality operators for both entities and value objects. In case of entities we will depend on Identity Map implemented in the ORM. It will make our code more consistent in context of object comparison.



