I'm creating a multilayered application, having an asp.net mvc application as the highest layer.
The architecture is the following (---> means references):
Presentation layer ---> Service Layer ---> Business layer ----> Data access layer ----> Database
Furthermore, there is a layer called "Infrastracture" which is referenced by all layers.
Each layer has it's own entities. For example: in the presentation layer we might have UserViewModel, in the service layer UserDTO, in the business layer UserBDO and finally, in the data access layer, User.
The automapper is used to automate the conversion between different types.
I read that some developers suggest to place the mappings creation in Global.asax, but it's obvious that if you have a multilayered application you can not create all mappings there. You can't map User with UserBDO in the presentation layer.
So, I'm asking the cleanest way to manage the mapping centralization in a multilayred application. You can even suggest changes in the architecture.
I suggest you already have the answer - if you cann't access all your types in single place - just split the mapping configurations into several parts. This solution is more maintainable in large projects (just imagine 100 or 1000 mappings in one configuration). For example, we use specific mapper to convert third-party WCF contracts to custom DTOs. This mapper is located in separate project together with WCF client. So contracts and mappings are not accessible from outside.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With