Good software architecture practice says that the presentation layer does not must know the domain layer. I'm trying to make this isolation between these layers, but the which is making this separation difficult is the mapping framework of objects, AutoMapper.
I have the following scenario:
Presentation Layer > Application Layer > Domain Layer
In the Domain layer I have the Client entity. In the Presentation layer I have the ClientViewModel.
To map these classes, I use the AutoMapper. The problem is that your configuration is done in the Presentation layer, so that this layer has who know the domain.
//Método da classe DomainToViewModelMappingProfile que está na Presentation
protected override void Configure()
{
// Faz referência ao Cliente do domínio.
Mapper.CreateMap<Cliente, ClienteViewModel>();
}
// Métodos da classe ClienteMapper
public static ClienteViewModel MapearClienteParaClienteViewModel(Cliente cliente)
{
return Mapper.Map<Cliente, ClienteViewModel>(cliente);
}
public static Cliente MapearClienteViewModelParaCliente(ClienteViewModel clienteView)
{
return Mapper.Map<ClienteViewModel, Cliente>(clienteView);
}
I tried to play AutoMapper in the Application layer, but as it references the domain does not refer to the Presentation, because there is a problem of circular depedence.
What would be the best way to do this isolation?