I have done a lot of reading recently about Always Valid domain entities. I have come to believe that in order to ensure the entities are always valid I need to:
1) Remove primitive obsession and put validation/domain rules in the value object constructors as explained here: https://enterprisecraftsmanship.com/2016/09/13/validation-and-ddd/. 2) Put validation/domain rules in the constuctor of entities or the property setters as explained here: http://gorodinski.com/blog/2012/05/19/validation-in-domain-driven-design-ddd/.
However, I then look at some Open Source projects such as this one: https://github.com/gregoryyoung/m-r. From what I understand the author of this project is an advocate of the always valid domain model and yet I look here at the InventoryItem class: https://github.com/gregoryyoung/m-r/blob/master/SimpleCQRS/Domain.cs. I notice that I am able to do this:
InventoryItem inventoryItem = new InventoryItem();
or this:
InventoryItem inventoryItem2 = new InventoryItem(Guid.Empty,null);
In my mind this means the entity is initialised in an invalid state. This seems to be the case in all of the other Open Source projects I have looked at recently as well e.g. this one: https://github.com/dcomartin/DDD-CQRS-ES-Example/blob/master/src/Domain/Customer.cs.
I realise there is Contextual validation in these open source project (https://martinfowler.com/bliki/ContextualValidation.html). I also realise that ORMs need a default empty constructor if mapped to the domain model.
Is a domain object in a valid state if it is initialised with default values using a zero arguement constructor/initialised with empty/null values?