c# - Where is the call to persistence in the domain driven design -


i know there lot of similar information online , on stackoverflow, i'm still not sure put logic of persistence project. don't yet use orm, ioc , unitofwork concepts (too new stuff beginner in ddd world).

i see 2 options order model:

  1. inside domain assembly there order class , iorderrepository interface. order class has private instance of iorderrepository passed in constructor. order class has public insert method, calls iorderrepository.insert method. actual implementetion of repository in orderrepository class of infrastructure layer. service layer contain orderservice class instantiates model appropriate repository , calls order.insert(). bad: have inject interface (or multiple instances) of repository model class, persistence logic inside model. good: has done before or after insert method called , nicely fit insert method of order class, example raising domain events or whatever.
  2. in model assembly there order class. service layer creates new order , new orderrepository , executes orderrepository.insert(order).

could please explain concept better in simple words (explain i'm five).

your domain classes should focused on business logic of domain only, , should persistent ignorant (i.e. persistence should separated business logic). adding persistence-related operations violates single responsibility principle. dependency on repository makes domain classes complex, instead of being simple poco entities.

let's think design coding point. have provide repository instance each order, , call order.insert() order pass repository have injected order. sounds complicated. simpler use repository.save(order). it's ok have crud methods on class (see active record pattern). approach when don't have complex domain model.

i think best place persistence of domain application services (maybe call layer service layer). load entities repositories, perform operations (it simple operations on entities, or calls domain services), , state of domain gets saved.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -