2

I have some data in my ERP that is formed in a very odd way (think a HTML field that contains many different fields, formatted in HTML that need to be pulled out using XPath).

Is the transformation of this data into the model fields the job of the repository? Or should the repository only deal with getting the records from the database and then have a service or a transformer of some sort that turns this HTML into the individual fields?

My repository returns an IList<Product>, however this model contains all the fields that need to be filled out. If I wanted to correctly return this type, I would have to pull all the fields out of the HTML field and set them, which doesn't feel like it belongs in the repository.

I've also seen something similar where you pass in to your repository something like an IProductTransformer.

Another option is to have separate models... one for the result of the database call and one for how I want to interact with the model in the program code.. and then map these through a transformer?

1 Answer 1

3

Outside the repository, your application must not know anything about the storage and data formats of your repository. Consequently, the data transformation must happen somewhere inside your repository. For the purpose of data transformation, the repository may contain a dependency on an item performing the transformation, like your IProductTransformer.

1
  • Great. Is Transformer the correct name of this pattern of changing one object to another whilst making changes to it on the way? Or is there a better term? I looked at the Adapter pattern but not sure if what I'm doing here is adapting or even mapping.
    – Lock
    Commented Jul 18, 2017 at 7:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.