I can support all your recommendations. Had an app with generated DTO and few additional methods. And inheritance from a basic DTO. Over the years, this has evolved into DTOs for every use case. Especially the division into request and response DTO has made the code more maintainable.
Watch out when you have to convert a DTO to a database record using the “id” field. Since the “id” field will try to automatically map towards the id field of the database record, resulting in an InvalidCastException (since often, a database id is defined as integer)
Hi, if I don't have all dto parameters in one time, for example in blazor form, should i use two different models, one mutable that stores form datas and One immutable dto that is built from the mutable model?
Most likely you are not in need of a dto. Assuming you are on the frontend with blazor, you will need a mutable object to fill in the data. Then, when all your data is ready to be sent over to the backend, create a dto. In short, if you are handling an object, causing mutation, most like it's not a dto.
What about readonly computed properties like FullName => $"{FirstName} {LastName}". I often use readonly computed properties which transforms the data iny my Dtos. The other system will just see it as another property. What you think about it?
records are a very convenient and concise way to define data structures but there is no simple way to validate that the parameters passed to the primary constructor are valid. I found some trick recently, but it is not very intuitive so i rarely use it ▶ ruclips.net/video/GJ8f9r97YTA/видео.html
Its not a matter of preferrence. Should always be using record for safety today. Thats the problem with c#, so many alternatives which doesn’t good anymore.
I use records too, but only include mandatory fields in constructor, optional are init properties in the record.
Great approach
I can support all your recommendations. Had an app with generated DTO and few additional methods. And inheritance from a basic DTO. Over the years, this has evolved into DTOs for every use case. Especially the division into request and response DTO has made the code more maintainable.
Thanks for sharing!
Love this video. Thank you!
Thank you 🙏
How do we make authentication between those dll calls that will not greatly slow the dll's we are using for dto. Any package suggestion?
What kind of question is that? It makes no sense at all.
Watch out when you have to convert a DTO to a database record using the “id” field. Since the “id” field will try to automatically map towards the id field of the database record, resulting in an InvalidCastException (since often, a database id is defined as integer)
Hmm. What do you mean, any example?
Hi, if I don't have all dto parameters in one time, for example in blazor form, should i use two different models, one mutable that stores form datas and One immutable dto that is built from the mutable model?
Most likely you are not in need of a dto. Assuming you are on the frontend with blazor, you will need a mutable object to fill in the data.
Then, when all your data is ready to be sent over to the backend, create a dto.
In short, if you are handling an object, causing mutation, most like it's not a dto.
I have no experience with blazor. Isn't it the case of MVVM? Model-view-view-model?
@@gui.ferreira not exactly, Is component based model
@@alfonsdeda8912 On that case, I don't see the object that supports the component as a DTO.
So i have to create One model to store mutable component data and create before saving the dto, Is correct?
What about readonly computed properties like FullName => $"{FirstName} {LastName}". I often use readonly computed properties which transforms the data iny my Dtos. The other system will just see it as another property. What you think about it?
There are some use cases where that approach is useful. Example: retro compatible changes
thanks
records are a very convenient and concise way to define data structures but there is no simple way to validate that the parameters passed to the primary constructor are valid. I found some trick recently, but it is not very intuitive so i rarely use it ▶ ruclips.net/video/GJ8f9r97YTA/видео.html
I love how you explained the 'required' keyword, your channel needs more subscribers.
Its not a matter of preferrence. Should always be using record for safety today. Thats the problem with c#, so many alternatives which doesn’t good anymore.
Moore Kenneth Hall Daniel White Melissa