Project: Mapper
This project is an updated version of the Clean Architecture code from the last chapter, which contains both a data model and a domain model. I used that version to showcase the mapping of both data to domain and domain to DTO. If you don't need a data model, don't create one, especially using Clean Architecture. Nonetheless, the goal is to demonstrate the design's versatility and encapsulate the mapping of entities into mapper classes to extract that logic from the repositories and the controllers.
First, we need an interface that resides in the Core
project so the other projects can implement the mapping that they need. Let's adopt the second design that we saw:
namespace Core.Interfaces { public interface IMapper<TSource, TDestination> { TDestination Map(TSource entity); } }
With that interface, we can start by creating the data mappers. Since we are mapping Data.Models.Product
to a Core.Entities.Product
and...