When you are working with a multi-tier application very often you run into task of converting objects in one layer to objects in another layer. This could be converting database objects into domain objects, service objects into domain objects, domain object into view models, etc.
I've seen it being done in multiple ways, those include:
- In-line conversion
- Creating a translator class with static helper methods
- Using extension methods to simplify conversion
- Overriding cast operators
- Creating sepearate mapper classes for every possible translation
- Utilizing solutions such as automapper
What would be the "proper" way to handle it. The application I currently work with utilizes separate mapper class for every possible translation, and although it has benefits of testability we are using dependency injection and we have to pass all those mappers as dependencies in the constructor.
Has anybody figured out a better way to do it?
I am using .NET stack here (EF +Business Layer + MVC)