Isolate Presentation Layer Domain

0

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?

    
asked by anonymous 23.10.2018 / 18:01

1 answer

1

I would use dependency injection interfaces, and one more layer of crosscutting to map through the projects the required classes with their interfaces.

In this project in Eduardo Pires github contains a project developed with good practices and Design Patterns among other design standards. Even it uses the automapper ...

  

Equinox

     

The goal of this project is to implement the most widely used   and share with the technical community the best way to   develop great applications with .NET.

    
23.10.2018 / 22:57