How do read-only database views fit into the repository pattern?

后端 未结 3 972
北恋
北恋 2020-12-23 12:37

Example: Your database has a SQL view named \"CustomerOrdersOnHold\". This view returns a filtered mix of specific customer and order data fields. You need to fetch data fro

3条回答
  •  温柔的废话
    2020-12-23 12:53

    I think that it is fine to have a separate repository like "CustomerOrdersOnHoldRepository". The interface of the repository will reflect the fact that the objects are readonly (by not defining Save/Add/MakePersistent method).

    From How to write a repository:

    ... But there is another strategy that I quite like: multiple Repositories. In our ordering example there is no reason we can have two Repositories: AllOrders and SurchargedOrders. AllOrders represent a list containing every single order in the system, SurchargedOrders represents a subset of it.

    I would not call returned object an Aggrgate Root. Aggregates are for consistency, data exchange and life cycles. Your objects don't have any of these. It seems that they also can not be classified as Value Objects ('characteristic or attribute'). They are just standalone classes.

提交回复
热议问题