Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC multilayered application: where to place Automapper initialization? [closed]

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.

like image 221
Errore Fatale Avatar asked Nov 10 '22 04:11

Errore Fatale


1 Answers

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.

like image 151
Ilya Chumakov Avatar answered Nov 14 '22 22:11

Ilya Chumakov