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:
- inside domain assembly there
orderclass ,iorderrepositoryinterface.orderclass has private instance ofiorderrepositorypassed in constructor. order class has publicinsertmethod, callsiorderrepository.insertmethod. actual implementetion of repository inorderrepositoryclass of infrastructure layer. service layer containorderserviceclass instantiates model appropriate repository , callsorder.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 fitinsertmethod oforderclass, example raising domain events or whatever. - in
modelassembly thereorderclass. service layer creates neworder, neworderrepository, executesorderrepository.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
Post a Comment