R
Well, James, from what I understood your biggest problem is the job of turning Model into DTO, then DTO into ViewModel, ViewModel into DTO, then DTO into Model. With AutoMapper, part of the work would be done and you would have less problems, but before simply using a type solution, you can rethink your model as a whole. There are several design standards to meet your similar needs, logically no standard is perfect. First I think you should think which points are most relevant to you: development speed, decoupling, maintainability and etc.There is no perfect pattern when we define an architecture, we always have to give up some things to achieve others, there is no efficient maintenance without testing, decoupling without separation of layers and responsibilities, etc.Why use DTO (Data Transfer Object)? As the name itself says, data transfer object, when you have a system where you need to hold several queries and bring complete entities into separate queries becomes a problem, it is time to use a DTO.From what I said it is seeing how a problem repeats this code of transforming an object into another, it is against using the pattern on uncomplex screens, a simple example:User Creation Screen:DTO:public Guid Id {get;set;}
public string Nome {get;set;}
public string Cpf {get;set;}
public string Telefone {get;set;}
public string Email {get;set;}
public string Senha {get;set;}
ENTITY:public Guid Id {get;set;}
public string Nome {get;set;}
public string Cpf {get;set;}
public string Telefone {get;set;}
public string Email {get;set;}
public string Senha {get;set;}
On your screen you will have to perform validations, your ViewModel cannot equal your DTO, you need the user to confirm the E-mail and Confirm Password, you may need to send several other information to your screen.Now imagine if tomorrow you realize that it is better to separate Entity User in Physical Person and CredentialFor whatever reason. Your DTO traffics the data from the two entities between the layers, continues using a single screen, does not need to change your application, only your data access layer.With some tools like I quoted AutoMapper you can make your work of transforming an entity similar to another easy one, with only one line of code, and you can take advantage of the advantages of this pattern.What you need to preach always is the separation of responsibilities and simplicity, not always less code is the simplest, not always the most complex is the best, ponder your needs. Basically: Use AutoMapper to convert an object to another with the same properties. Leave your business rule in your domain and let your repository just be your link link with your database. In the rest try to evaluate what to do in each layer, and let each one do what is your responsibility.