Reducing Repositories to Aggregate Roots

前端 未结 5 527
不知归路
不知归路 2020-12-12 11:02

I currently have a repository for just about every table in the database and would like to further align myself with DDD by reducing them to aggregate roots only.

Le

5条回答
  •  一生所求
    2020-12-12 11:48

    If phone makes no sense w/o user, it's an entity (if You care about it's identity) or value object and should always be modified through user and retrieved/updated together.

    Think about aggregate roots as context definers - they draw local contexts but are in global context (Your application) themselves.

    If You follow domain driven design, repositories are supposed to be 1:1 per aggregate roots.
    No excuses.

    I bet these are problems You are facing:

    • technical difficulties - object relation impedance mismatch. You are struggling with persisting whole object graphs with ease and entity framework kind a fails to help.
    • domain model is data centric (as opposed to behavior centric). because of that - You lose knowledge about object hierarchy (previously mentioned contexts) and magically everything becomes an aggregate root.

    I'm not sure how to fix first problem, but I've noticed that fixing second one fixes first good enough. To understand what I mean with behavior centric, give this paper a try.

    P.s. Reducing repository to aggregate root makes no sense.
    P.p.s. Avoid "CodeRepositories". That leads to data centric -> procedural code.
    P.p.p.s Avoid unit of work pattern. Aggregate roots should define transaction boundaries.

提交回复
热议问题