domain driven design - DDD repository and factory -


in application few layers. in topic focus on domain , infrastructure layers.

i have repository interface clientrepositoryinterface in domain layer. , have implementation of interface clientrepositoryimpl in infrastructure layer.

but reconstitute object in middle of cycle of existence need factory(reconstitutionclientfactory). call factory in repository. book eric evans described normal practice.

but factory(reconstitutionclientfactory) should located? in domain or in infrastructure layer?

i think in domain... but! lower layer directly call higher layer! wrong, how right?

first of all, layers approach kinda obsolete. when talking layers think 'context', who's on top of isn't important.

the repository in charge of restoring object. factory creates new object. note different semantics. repository knows how saving/restoring to/from persistence done , depends on storage , method of access.

so, done inside repository i.e in infrastructure. if serialize things, need deserialize (this how document db things anyway). if you're using orm or store things in tables you'll query required data , repopulate object. orm easiest way since can use reflection populate private properties. in case orm factory.

one more thing, restoring, while technically can done domain factory, isn't factory's purpose because breaks layer boundaries. want keep persistence related in infrastructure.


Comments