J_PT
J_PT

Reputation: 489

Using AutoMapper Correctly

I m trying to learn how to use AutoMapper, I m trying to figure out how to use without having to couple different layers.

Example, I have DataLayer, BusinessLayer and UILayer. To transfer/map from DataLayer to BusinessLayer, I have to have references in BusinessLayer to the DataLayer Entites. The same happens if I try to To transfer/map from BusinessLayer to UILayer, in this case I would need to have references to the BusinessLayer from UILayer.

The solution here appears that we need an extra assembly (common/shared) between all layers that would do this automatically without needing to couple the DataLayer, BusinessLayer and UILayer with each other...

No sure how to do this, any example of this that I can use? How genereally this problem is addressed?

Upvotes: 0

Views: 228

Answers (1)

Matías Fidemraizer
Matías Fidemraizer

Reputation: 64943

Unless you invert the dependency between layers, it doesn't seem that bad.

Introducing UI dependencies in your business layer would be ugly, but since UI layer is on top of business layer, it's fine that you mix UI and business layer there.

At the end of the day, AutoMapper replaces what you would do manually: setting properties one by one from an object to other one. What would happen if you would do this without AutoMapper? I believe that you would need a reference of business layer in your UI layer to perform such mapping.

Upvotes: 1

Related Questions