0
votes

I am developing an application and trying to use a DDD approach. I modeled all my entities and aggregates in the domain. Now I would like to keep my validation logic in the domain, but I need to support some bulk import functionality(via a csv file). I need to validate the file and give the user information about the rows that need corrections.

What would be the best DDD way to do this? The validation logic is quite complex and I wouldn't like to duplicate the csv file validation in the domain. Also the file structure is a more flatten structure which is different from the domain aggregate. So even if I validate the aggregate the row information is lost.

1
I am not quite sure to understand the problem. If you have the validation for one raw, what stops you to apply the logic to a list instead?Dnomyar

1 Answers

0
votes

What would be the best DDD way to do this? The validation logic is quite complex and I wouldn't like to duplicate the csv file validation in the domain.

To accomplish something of this nature, you can use a Saga or Process Manager. It would maintain your position in the file and issue commands to your Aggregates to perform the file import. If the commands fail or are rejected then you can update the corresponding rows with the error messages that are produced by the domain.

Also the file structure is a more flatten structure which is different from the domain aggregate. So even if I validate the aggregate the row information is lost.

You could group the records in the file if necessary, but the saga should maintain a record of the line numbers and corresponding commands. You may choose to model the file itself as an Aggregate which will provide benefits as well. Eliding domain concepts such as this will make things more difficult in the future, but adding them to the design will come at the cost of time.

I can provide more detail if you can explain: Are you using DDD, CQRS, ES, queues, async, etc? As @Dnomyar explained, you might also help to explain where you are facing actual difficulties.