domain driven design - Responsibility of Factory or Repository to create aggregate root instances from existing data -
when materializing new aggregate root instances constructed pieces of data persisted via entities different bounded context when transitioning between irreversible states better domain driven design have responsibility of repository or factory.
home improvement contractor example
say have 1 aggregate root called proposal represents proposal home construction work. in separate bounded context have process in information proposal allowed copied formulate new workitem aggregate root track actual work done.
when formulating new workitem see @ least 2 possibilities of place responsibility:
- create method on workitemrepository takes proposal id argument , formulates existing workitem based on information proposal. workitem need have status value of type indicate whether still in proposal state or not , persisting workitem still in proposal state blocked persistence validation service. following approach strange since no new work items ever need created in work item's bounded context.
- create interface , concrete class pair workitemfactory exposes method such createworkitemfromproposal takes proposal id argument same thing repository method have done. option uses typical interface/implementation separate similar used repositories interface part of domain concrete implementation considered infrastructure. approach seems more flexible in long term on other hand requires separation of contract , implementation factories see more typically repositories , not services , factories in ddd. typical aggregate root factories not pull out of persistence each time invoked, should they?
for sake of above example may useful assume scenario proposal id remains same later work item id. in other words proposal , workitem different views of same underlying entity , used in separate domain contexts.
of course want welcome different options may have left out in short list above long within general conventions of domain driven design.
Comments
Post a Comment