Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DDD Object Persistence without Getters

I think I'm missing something really obvious but there is a lot of disagreement on domain objects and their persistence via a repository so it's hard to get a clear answer on this.

Assuming that

  • I've built a pure domain model that has NO dependencies on any other assemblies within my solution as DDD states with only one clear root aggregate.

  • I have a domain specific repository that persists the root aggregate,invoked by the service layer.

  • Internally the repository uses EF to persist the object along with its children

If avoid exposing getters (and definitely not setters) then how does my repository get access to the state of the object in order to actually persist it.

Options??

  1. Dependency injection into the domain model (DDD smell??)

  2. Getters only (DDD smell??)

Also there is the reverse issue pulling objects out of the DB. Initialisation via the constructor seems the only likely candidate.

like image 429
csherriff Avatar asked Oct 04 '22 20:10

csherriff


1 Answers

An ORM can get to the data inside objects via reflection. For example, NHibernate has various access strategies for properties which allow mapped classes to only have private fields with no getters or setters. I think EF should have similar facilities.

like image 150
eulerfx Avatar answered Oct 10 '22 03:10

eulerfx