Onion Architecture - Repository Vs Service?

后端 未结 6 1881
面向向阳花
面向向阳花 2020-12-23 09:53

I am learning the well-known Onion Architecture from Jeffrey Palermo. Not specific to this pattern, but I cannot see clearly the separation between repositories and domain s

6条回答
  •  执念已碎
    2020-12-23 10:22

    Repository pattern mediates between the domain and data mapping layers using a collection-like interface for accessing domain objects.

    So, repositories is to provide interface for CRUD operation on domain entities. Remember that Repositories deals with whole Aggregate.

    Aggregates are groups of things that belong together. An Aggregate Root is the thing that holds them all together.

    Example Order and OrderLines:

    OrderLines have no reason to exist without their parent Order, nor can they belong to any other Order. In this case, Order and OrderLines would probably be an Aggregate, and the Order would be the Aggregate Root

    Business logic should be in Domain Entities, not in Repository layer , application logic should be in service layer like your mention, services in here play a role as coordinator between repositoies.

提交回复
热议问题