I use records too, but only include mandatory fields in constructor, optional are init properties in the record.
@gui.ferreira3 ай бұрын
Great approach
@kitsurubami2 ай бұрын
Love this video. Thank you!
@gui.ferreira2 ай бұрын
Thank you 🙏
@christianschulz44753 ай бұрын
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.
@gui.ferreira3 ай бұрын
Thanks for sharing!
@bl1tz2293 ай бұрын
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)
@thelostrider13 ай бұрын
Hmm. What do you mean, any example?
@jindhk2 ай бұрын
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?
@marcobaccaro2 ай бұрын
What kind of question is that? It makes no sense at all.
@AboutCleanCode3 ай бұрын
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 ▶ kzbin.info/www/bejne/fXubl2yobpyMiqM
@WhichWazzockWantedEmailHandles3 ай бұрын
I love how you explained the 'required' keyword, your channel needs more subscribers.
@richardhaughton96333 ай бұрын
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?
@gui.ferreira3 ай бұрын
There are some use cases where that approach is useful. Example: retro compatible changes
@alfonsdeda89123 ай бұрын
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?
@DieDona3 ай бұрын
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.
@gui.ferreira3 ай бұрын
I have no experience with blazor. Isn't it the case of MVVM? Model-view-view-model?
@alfonsdeda89123 ай бұрын
@@gui.ferreira not exactly, Is component based model
@gui.ferreira3 ай бұрын
@@alfonsdeda8912 On that case, I don't see the object that supports the component as a DTO.
@alfonsdeda89123 ай бұрын
So i have to create One model to store mutable component data and create before saving the dto, Is correct?
@codeDotnet3 ай бұрын
thanks
@webbi15403 ай бұрын
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.