Building better DTOs in C#

  Рет қаралды 6,970

Gui Ferreira

Gui Ferreira

Күн бұрын

Пікірлер: 23
@allannielsen4752
@allannielsen4752 3 ай бұрын
I use records too, but only include mandatory fields in constructor, optional are init properties in the record.
@gui.ferreira
@gui.ferreira 3 ай бұрын
Great approach
@kitsurubami
@kitsurubami 2 ай бұрын
Love this video. Thank you!
@gui.ferreira
@gui.ferreira 2 ай бұрын
Thank you 🙏
@christianschulz4475
@christianschulz4475 3 ай бұрын
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.ferreira
@gui.ferreira 3 ай бұрын
Thanks for sharing!
@bl1tz229
@bl1tz229 3 ай бұрын
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)
@thelostrider1
@thelostrider1 3 ай бұрын
Hmm. What do you mean, any example?
@jindhk
@jindhk 2 ай бұрын
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?
@marcobaccaro
@marcobaccaro 2 ай бұрын
What kind of question is that? It makes no sense at all.
@AboutCleanCode
@AboutCleanCode 3 ай бұрын
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
@WhichWazzockWantedEmailHandles
@WhichWazzockWantedEmailHandles 3 ай бұрын
I love how you explained the 'required' keyword, your channel needs more subscribers.
@richardhaughton9633
@richardhaughton9633 3 ай бұрын
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.ferreira
@gui.ferreira 3 ай бұрын
There are some use cases where that approach is useful. Example: retro compatible changes
@alfonsdeda8912
@alfonsdeda8912 3 ай бұрын
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?
@DieDona
@DieDona 3 ай бұрын
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.ferreira
@gui.ferreira 3 ай бұрын
I have no experience with blazor. Isn't it the case of MVVM? Model-view-view-model?
@alfonsdeda8912
@alfonsdeda8912 3 ай бұрын
@@gui.ferreira not exactly, Is component based model
@gui.ferreira
@gui.ferreira 3 ай бұрын
@@alfonsdeda8912 On that case, I don't see the object that supports the component as a DTO.
@alfonsdeda8912
@alfonsdeda8912 3 ай бұрын
So i have to create One model to store mutable component data and create before saving the dto, Is correct?
@codeDotnet
@codeDotnet 3 ай бұрын
thanks
@webbi1540
@webbi1540 3 ай бұрын
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.
@BloomfieldBlanche
@BloomfieldBlanche 3 ай бұрын
Moore Kenneth Hall Daniel White Melissa
5 Rules For DTOs
17:56
Ardalis
Рет қаралды 46 М.
Building Complex Objects in a Simple Way with C#
12:19
Gui Ferreira
Рет қаралды 9 М.
Quilt Challenge, No Skills, Just Luck#Funnyfamily #Partygames #Funny
00:32
Family Games Media
Рет қаралды 55 МЛН
The New Option and Result Types of C#
15:05
Nick Chapsas
Рет қаралды 82 М.
How to Organize Your ASP.NET Program.cs File
15:40
Gui Ferreira
Рет қаралды 6 М.
Does AI Coding Make Programmers Faster
11:27
Ian Sinnott
Рет қаралды 334
Completely Get Rid of Exceptions Using This Technique
19:24
Milan Jovanović
Рет қаралды 27 М.
DTOs: The Good, The Bad, and The Tradeoff
8:47
Gui Ferreira
Рет қаралды 3,5 М.
The Right Way to Check for Null in C#
9:35
Nick Chapsas
Рет қаралды 99 М.
What’s the Result Type Everyone Is Using in .NET?
14:47
Nick Chapsas
Рет қаралды 114 М.
These coding projects give you an unfair advantage
8:13
Jason Goodison
Рет қаралды 1,1 МЛН
Easy Email Verification in .NET: FluentEmail + Papercut
19:29
Milan Jovanović
Рет қаралды 10 М.