DDD - the rule that Entities can't access Repositories directly

后端 未结 11 1414
栀梦
栀梦 2020-11-28 00:24

In Domain Driven Design, there seems to be lots of agreement that Entities should not access Repositories directly.

Did this come from Eric Evans Domain Driven Desi

11条回答
  •  抹茶落季
    2020-11-28 00:54

    To me this appears to be general good OOD related practice rather than being specific to DDD.

    Reasons that I can think of are:

    • Separation of concerns (Entities should be separated from the way they are persisted. as there could be multiple strategies in which the same entity would be persisted depending on usage scenario)
    • Logically, entities could be seen in a level below the level in which repositories operate. Lower level components should not have knowledge on the higher level components. Therefore entries should not have knowledge on Repositories.

提交回复
热议问题