Answer the question
In order to leave comments, you need to log in
How to properly use Dto objects?
Hello! The question arose of how to use Dto objects correctly, or what am I doing wrong! The application is divided into 3 layers, DataAccess, Business,Presentation, from the Business layer I call the methods that lie in DataAccess and materialize them into a specific model, now the question is, for example, I have a GetUser method, for which I need it to return UserId, UserName , and there is a GetUserInfo method, for which you need it to return UserEmail, UserPassword, i.e. it turns out that for each method you need to create your own Dto object? Or is it possible to somehow do without Dto objects, or am I doing something wrong?
Answer the question
In order to leave comments, you need to log in
As far as I know, there are models for presentation (DTO or xxxViewModel - the end user sees them and passes data to them for controllers), and there are Entity entities that are already in the database (they do mapping between them).
In order not to sculpt validation, hide some fields or add temporary ones, they were separated. The application will become safer, isAdmin = true will not stick, even if you forget to remove the property in the binding.
If a non-complex object arrives at the controller, DTO is not necessary.
If it’s complex, then it’s easier to do, there won’t be many of them anyway, but it’s easy to validate through ModelState.IsValid and attributes.
Here is a great site metanit.com/sharp
This is just a godsend, in a couple of days you can get acquainted with all the main points on ASP.NET.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question