domain-driven-designsharp-architecture

Sharp Architecture Value Objects


I'm checking out Sharp Architecture's code. So far it's cool, but I'm having problems getting my head around how to implement DDD value objects in the framework (doesn't seem to be anything mentioning this in the code). I'm assuming the base Entity class and Repository base are to be used for entities only. Any ideas on how to implement value objects in the framework?


Solution

  • In Sharp Arch there is a class ValueObject in namespace SharpArch.Domain.DomainModel. This object inherits from BaseObject and overrides the == and != operators and the Equals() and GetHashCode() methods. The method overrides just calls the BaseObject versions of those two methods which in turn uses GetTypeSpecificSignatureProperties() method to get the properties to use in the equality comparison.

    Bottom line is that Entity's equality is determined by

    1. Reference equality
    2. Same type?
    3. Id's are the same
    4. Comparison of all properties decorated with the [DomainSignature] attribute

    For ValueObjects, the BaseObject's Equals method is used

    1. Reference equality
    2. Same type?
    3. Compare all public properties

    This is a little bit simplified, I suggest you get the latest code from github and read through the code in the mentioned 3 classes yourself.

    Edit: Regarding persistence, this SO question might help. Other than that, refer to the official NH and Fluent NH documentation