This is a really good question - and something that I realized when trying to use ORM for domain objects. My domain objects expose public properties of type IEnumerable that return ReadOnlyCollection, so the only way to add to the collection is to call the custom Add method on the parent.
In my opinion, no, you donβt go too far to create your objects this way.
I fully justify attempts to encapsulate your objects as much as possible, while maintaining private fields and providing public methods that are atomic, clearly show intent and ensure that objects can only exist in an acceptable state. If this means using raw ADO.NET, then so be it. For me, so that domain objects are strictly built, I should not violate the choice of DAL technology.
However, I HATE writing DAL code for the boiler plate and writing raw ADO.NET with sprocs will make my head these days. I realized that the DAL record for encapsulated domain objects becomes MUCH MUCH MUCH easier if you use Event Sourcing as a mechanism to save your domain objects. All you need is an event table that stores all your events as serialized data. Since the domain objects themselves are not saved, it does not matter that the repositories do not have access to the List property on the domain object. Then your unit of work "raises" those events that the query component can handle, which fills / updates any tables that you need to use simple DTO and ORM.
Here is an example of an event source
CQRS and event sources are actually designed to provide high scalability and, by definition, include many asynchronous operations based on a βconsistentβ paradigm. However, even when working on projects that do not require such a level of scalability, I believe that these templates synchronously provide a mechanism for my domain objects to be fully encapsulated, at the same time without having to write one line of DAL code with manual processing, while preserving MASSIVE the amount of time and providing a complete audit trail (events) for each action taken, thrown for free. It is also an invaluable tool if your system needs to communicate with third-party systems through messaging.
David masters
source share