Несколько агрегатов / хранилищ в одной транзакции

У меня есть платежная система, как показано ниже. Оплата может быть произведена через несколько подарочных купонов. Подарочные купоны выдаются вместе с покупкой. Клиент может использовать этот подарочный купон для будущей покупки.

Когда оплата производится с помощью подарочного купона, столбец UsedForPaymentID в таблице GiftCoupon необходимо обновить с помощью этого идентификатора платежа (для идентификатора подарочного купона).

GiftCouponIDs уже доступны в базе данных. Когда покупатель создает подарочный купон, на нем печатается GiftCouponID. Оператору необходимо ввести этот CouponID в систему, чтобы совершить Платеж.

Для операции MakePayment () необходимы два репозитория.

Gift Coupon Repository Payment Repository

КОД

//Use GiftCouponRepository to retrieve the corresponding GiftCoupon object.

Это предполагает использование двух хранилищ для одной транзакции. Это хорошая практика? Если нет, как мы можем изменить дизайн, чтобы преодолеть это?

Reference: In DDD the Aggregate should represent the transactional boundary. A transaction that requires the involvement of more than one aggregate is often a sign that either the model should be refined, or the transactional requirements should be reviewed, or both. Is CQRS correct for my domain?

enter image description here

C # CODE

public RepositoryLayer.ILijosPaymentRepository repository { get; set; }

public void MakePayment(int giftCouponID)
{
    DBML_Project.Payment paymentEntity = new DBML_Project.Payment();
    paymentEntity.PaymentID = 1;

    DBML_Project.GiftCoupon giftCouponObj;

    //Use GiftCouponRepository to retrieve the corresponding GiftCoupon object.     

    paymentEntity.GiftCouponPayments = new System.Data.Linq.EntitySet<DBML_Project.GiftCoupon>();
    paymentEntity.GiftCouponPayments.Add(giftCouponObj);

    repository.InsertEntity(paymentEntity);
    repository.SubmitChanges();
}

Ответы на вопрос(4)

Ваш ответ на вопрос