Project – Mapping service
The goal is to simplify the implementation of the mapper façade with a universal interface.
We are going to use our third diagram to achieve that goal. Here's a reminder:
Figure 13.4 – Object mapping using a single IMapper interface
Instead of naming the interface IMapper, I found IMappingService to be more suitable because it is not mapping anything; it is a dispatcher, sending the mapping request to the right mapper. Let's take a look:
namespace Core.Interfaces
{
public interface IMappingService
{
TDestination Map<TSource, TDestination>(TSource entity);
}
}
That interface is self-explanatory; it maps any TSource to any TDestination.
On the implementation side, we are leveraging the Service Locator pattern, so I called the implementation ServiceLocatorMappingService:
namespace Web.Services
{
public class ServiceLocatorMappingService : IMappingService
...