Implementing a mapping façade
We studied façades already; here, we explore another way to organize our many mappers by leveraging that design pattern.
Instead of what we just did, we create a mapping façade to replace our aggregate services. The code consuming the façade is more elegant because it uses the Map
methods directly instead of the properties. The responsibility of the façade is the same as the aggregate, but it implements the interfaces instead of exposing them as properties.
This example shares a lot of the same code as the aggregate services example we just explored, so we start to look at the new code that replaces the IProductMappers
interface and the ProductMappers
class:
using Shared.Contracts;
using Shared.Mappers;
using Shared.Models;
namespace MappingFacade;
public interface IProductMapperService :
IMapper<Product, ProductSummary>,
IMapper<InsertProduct, Product>,
IMapper<UpdateProduct, Product>...