I have problem with consistency paranoia in DDD. I still want to validate relation between objects and sometimes it feels like I’m over-validating stuff. For example:
Aggregate1: Payment(id, merchantId, posId)
Aggregate2: Merchant(id)
Aggregate3: Store(id, merchantId)
Aggregate4: Pos(id, storeId, merchantId)
Payment payment = merchant.createPayment(pos, store); // here i did validations
later, second transaction:
payment.prepareRequest(pos, merchant, store);
Is it ok to firstly check if payment.wasCreatedBy(pos)
and if pos.belongsTo(store)
and if store.belongsTo(merchant)
and then, when everything is fine do actual request preparation with lets say:
PosInfo posInfo = pos.info(); StoreInfo storeInfo = store.info(); MerchantInfo merchantInfo = merchant.info(); return new PreparedRequest(posInfo, storeInfo, merchantInfo);
Or should I just do this in app service:
PosInfo info = posRepository.find(posId).info(); StoreInfo info = storeRepository.find(storeId).info(); MerchantInfo info = merchantRepository.find(merchantId).info(); Payment payment = paymentRepository.find(paymentId); PreparedRequest req = payment.prepareRequest(posInfo, merchantInfo, storeInfo);
without any validation? Should I expect that application service will prepare data correctly or should I prevent creating such “request” when some relation is invalid – be paranoid?