Isolate presentation layer domain

Asked

Viewed 174 times

0

Good software architecture practice says that the presentation layer does not You must know the domain layer. I’m trying to make this isolation between these layers, but the that is hindering this separation is the mapping framework of objects, the 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 Clienteviewmodel.

To map these classes, I use the Automapper. The problem is that your configuration is made in the Presentation layer, and this way ends that this layer has who knows 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 the Automapper on the Application layer, but how it references the domain not to reference Presentation, because there is a problem of circular function.

What would be the best way to do this isolation?

1 answer

1


I would use interfaces for dependency injection, and another layer of crosscutting to map through the projects the classes needed with their interfaces.

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

Equinox

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

  • Thanks Nicolas! But when downloading some projects do not load.

  • The Equinox.UI.Site and Equinox.Webapi projects have failed to load: the specified 'Microsoft.NET.Sdk.Web' SDK could not be found.

  • 1

    So guy this project stays in Dot.Net Core, which has the SDK in visual studio 2017, so if you try to load with visual studio 2015 down they don’t have the compatibility. an option and load with the visual code. Visual Code

Browser other questions tagged

You are not signed in. Login or sign up in order to post.