Multiple Aggregates / Repositories in one Transaction

后端 未结 4 1669
长发绾君心
长发绾君心 2020-11-29 01:36

I have a payment system as shown below. The payment can be made through multiple gift coupons. The gift coupons are issued along with a purchase. The customer can make use o

4条回答
  •  温柔的废话
    2020-11-29 01:40

    There's nothing wrong with using two repositories in one transaction. As JB Nizet points out, that's what a service layer is for.

    If you're having issue keeping the connection shared, you can use the Unit of Work1 pattern to control the connection from the service layer and have the factory that provides the data context to your repositories supply the OoW instance.

    1 The EF/L2S DataContext is itself a UoW implementation, but it's nice to have an abstract one for the service layer for situations such as these.

提交回复
热议问题