Главная
Dating and Meetings

The 3 Biggest Mistakes of Object Mapping in .NET




Video quality The size Download

Информация о The 3 Biggest Mistakes of Object Mapping in .NET


Название :  The 3 Biggest Mistakes of Object Mapping in .NET
Продолжительность :   11.33
Дата публикации :  
Просмотров :   55 rb


Кадры The 3 Biggest Mistakes of Object Mapping in .NET





Описание The 3 Biggest Mistakes of Object Mapping in .NET



Коментарии The 3 Biggest Mistakes of Object Mapping in .NET



@nickchapsas
Check out my new course From Zero to Hero: Logging in NET and use code LOG20 at checkout for 20 off: bitly/loggingdotnet valid for the first 400 purchases!
Comment from : @nickchapsas


@brantleyblanchard7395
I disagree strongly on the last point After watching Jimmy Bogard's NDC talk called "Crafting Wicked Domain Models", I changed my position on the POCO vs Domain argument
Comment from : @brantleyblanchard7395


@willian-rattis
Nick I really love your videos, but you speak too fast 😂 brbrI’m from 🇧🇷 and our English it’s really bad 😂 brbrFirst, thanks for sharing this content
Comment from : @willian-rattis


@krccmsitp2884
Full Ack!
Comment from : @krccmsitp2884


@TheDDG0
Okay boss, but what do we do when we are having to map a calculated value? What to do instead of injecting the service into mapper?
Comment from : @TheDDG0


@sujitwarrier4857
We had a lot of IMapper mocking in my project We had everyone fix it after a full code review
Comment from : @sujitwarrier4857


@EarthianZero
I’ve always thought these were common sense, until I found business logic in the mapProfile file at work
Comment from : @EarthianZero


@niltonnascimento1246
It's still unclear for me the problem with operators in the dto class All the arguments sounds like just a preference
Comment from : @niltonnascimento1246


@fakhrulhilal
I love implicit/explicit operator, it works like a magic 😆
Comment from : @fakhrulhilal


@thescarletcars
now I feel proud of myself because I came up with the extension method idea by myself one day But thanks I've seen other mappers you mentioned in some of the project and never realized whats wrong with them
Comment from : @thescarletcars


@user-qp8bt7gq4b
My entire project is about mapping one things to another, so mappers are the heaviest thing in my code Of course I have services injected into mappers I can't decide a I doing something wrong or the video is just about other thing that named "mapper" too The difference is that in video we are talking about having the different contracts for the same (roughly speaking) object But in my project mappers create a completely different object (using the data from the original object, yes, but still the result object is completely different) Guys, what do you think? Maybe my mappers should actually be named as mappers? :D
Comment from : @user-qp8bt7gq4b


@AthelstanEngland
This is all a bit above me at the moment, but I do love how animated you are over it!! As my skills increase I dare say I'll come back to this video
Comment from : @AthelstanEngland


@towelandtea42
I don't see the problem of mocking Mapper The problem lies in not unit testing the mapping profiles if you choose to do so The tests are ridiculously easy to write and it's a better way of finding mapping mistakes than having them jumbled up with the logic inside the caller method I find it more reasonable, as I can put some thought into generating good random data to make sure they're working properly instead of generating whatever while I'm worried about testing business logic
Comment from : @towelandtea42


@ZilesFiles
Started watching this to see if I do something I shouldn't For using C# for around 15 years, I have no idea what a mapper is 😅
Comment from : @ZilesFiles


@jeguerrero
I have never liked using libraries to do object mapping Extension methods are a simple and reusable option for mapping and with extension methods is not necessary to learn the details of a library just to map an object
Comment from : @jeguerrero


@Devinfrbs
I use the implicit method - Guilty - But only to go up the application tree, not downbrbrA business object should never know anything about converting DOWN to the DTO object That's for the repository to care about
Comment from : @Devinfrbs


@tommaple
DTO stands for Data TRANSFER Object, not Data Mapping Object I agree that putting there mapping logic is not good solution, it kind of breaks SRP (Single Responsibility Principle) for DTOs, although I don’t think it’s terrible—there are worst things that people dobrbrI usually create 2 interfaces: IMapper and ICollectionMapper, the last one with implementation: CollectionMapper that uses IMapper to map a single element and just orchestrates using it for collections or sequences with the support of null inputs if necessarybrbrPersonally, I prefer to have it injected—I treat it as a component I mock it only for very rare, specific scenarios (eg to test very specific cases that require very specific data, and mocking the mapper makes the test more readable)
Comment from : @tommaple


@DigitalNomadOnFIRE
Mistake 1brUsing Entity FrameworkbrbrThere is no mistake 2
Comment from : @DigitalNomadOnFIRE


@Spenchik
How to right hash and dehash Guid Id from database, and not send it to FE, with automapper ? Like Dto with string Id, and Guid Id in Entity ?
Comment from : @Spenchik


@chrismantonuk
That’s the problem with mapping You’re damned if you do, damned if you don’t Yes AutoMapper is god awful - but manual mapping is error prone and time consuming too There doesn’t seem to be a perfect solution I liked your extension method idea though, I’ll give that one a try
Comment from : @chrismantonuk


@SudhanshuMishraTheOne
I’ve tended to use the extension method based approach you show towards the end It is debug-able, straightforward and does not require knowledge of a 3rd party library brSolid advice about unit tests and avoiding mock of auto mapper
Comment from : @SudhanshuMishraTheOne


@jtesh
I use the explicit / implicit operators on the DTOs I think this is ok
Comment from : @jtesh


@GlebWritesCode
Another problem is AutoMapper doesn't support injecting dependencies into profiles - you have to write code for it to do so brAlso - I think visibility isn't the problem when you inject a dependency
Comment from : @GlebWritesCode


@BrianBehm
I trust Jimmy
Comment from : @BrianBehm


@KingOfBlades27
I can totally understand why we shouldn't use serviced inside our mapping classes But what exactly is the solution? Just pass needed values as parameters? So in this example just a good encrypted password that came from the service earlier?
Comment from : @KingOfBlades27


@sergius_carp
Hi Nick Thanks for the video It seems you don't like using libraries like AutoMapper and others to map objects Can you please share approaches to map from an entity to a DTO? An entity might contain a picture property (eg user photo) or just huge number of properties and the corresponding DTO has just few of those Obviously it is not efficient to load a full entity from the DB when we just need few properties
Comment from : @sergius_carp


@dmitrykim3096
Its a common mistake among developers to use and create multiple tools to make it faster to code The problem is that the priorities are now different, exliciitness and readability are the top priorities leasing to less errors and easier maintenance
Comment from : @dmitrykim3096


@nikogaurun7406
Hi @nickchapsas, we want to use a service within the mapping to retrieve an id for a string value (CompanyName -> CompanyId) After viewing this video I have doubts that this is a good idea Whats your opinion in this case?
Comment from : @nikogaurun7406


@rosenpetrov4251
About the first mistake with business logic Doest that mean that the password should be left empty in the mapper and set in the service?
Comment from : @rosenpetrov4251


@andr6087
AutoMapper is Evil like Russia
Comment from : @andr6087


@DanielChenery
I disagree with the testing logic It's a unit test, specific about that code Mocking a mapper has the benefit of asserting the right object was passed in by reference and also allows for much cleaner setups in your tests as you can pass in empty objects and mock any response
Comment from : @DanielChenery


@lambda-snail
Maybe they mock the IMapper because they are making api or database calls from the mapper? :D
Comment from : @lambda-snail


@janskala3834
The reason I use AutoMapper is ProjectTo And the fact that AutoMapper can reuse existing mappings in ProjectTo method Is there a way how to achieve this manually? Because as far as I know, calls to extension methods cannot be translated into Expression, so the mapping will be done in memory and not translated to SQL
Comment from : @janskala3834


@AlFasGD
I find object mapping to be the problem in the first place Why would you need multiple objects with the exact same properties copied over when you can share one single object that has those properties, and pass it down to whatever you feel like If you need specific rules for serialization, avoid defining them from atttributes and use another technique like the builder that each serialization system provides
Comment from : @AlFasGD


@mykolakriukov1252
Really cool topic, had several issues in my mind that Nick mentioned, now I've changed my outlook Thank you!
Comment from : @mykolakriukov1252


@emanuelrodriguez3155
great video! what about re using a mapping into the projection of EFCore? is that posible?
Comment from : @emanuelrodriguez3155


@StefanoTempesta
Solution is even easier, don't map objects Ever
Comment from : @StefanoTempesta


@DiomedesDominguez
I thought that I was making the first mistake, but after further inspection I'm not injecting business rules into the mapping For context, I have an old web application that uses MSSQL geography data types because at that moment I thought that it was a good idea for be used with PowerBI and other reports, but my DTO uses classes with net geography data types which, as you may know, are not 100 data types compatible with their database's counterparts, so in my mapper I have a FromText method to do the conversionbrbrI know that in some repository class/methods I do make the second mistake, so I'm taking notes for future projects
Comment from : @DiomedesDominguez


@sacharkin
Thanks for the hints I personally sometimes mock my mapper and do not use the profile directly It feels always wrong, and now I know it was wrong
Comment from : @sacharkin


@Michel000000001
Hallelujah Can't hear it enough that people don't like automapper, because of all the reasons you say Though I see it used on nearly all the projects I work on, because "it's so easy" and most of the time "You shouldn't program what can be done automatically" However, Especially in your account example, you see that there is nothing automatically about some mappings All mappings need carefull attention, because you need to say (imo) what has to be done when source properties are not present or target properties are not present, worst case you end up with default values for (new) properties
Comment from : @Michel000000001


@Marfig
It's great that you point out problem 2 I see it and other variations of it quite a bit, and sadly it can often go unnoticed on pull requests It's an unfortunate by-product of the dogmatic way so many people teach dependency injection and unit testing, without ever explaining the true semantic purpose of mocking in the context of a unit test, which would ALWAYS require including an explanation of what you don't want to mock in a unit test
Comment from : @Marfig


@Marfig
Sorry for the poking, but I think the biggest take for problem number one is that it violates separation of concerns Saying too many times it doesn't belong there won't help anyone unless you explain why it doesn't belong there
Comment from : @Marfig


@stephenyork7318
Copy constructors copying from a different? Eww I’m stunned anyone would even think to do that Create video Nick
Comment from : @stephenyork7318


@watchchat
Nick, for the DTO scenario…the adapter pattern
Comment from : @watchchat


@JeremyConnor
Great video, fully agree!
Comment from : @JeremyConnor


@istovall2624
The implicit operator killed me at an ehr job stuff was just magically converting to another thing until I discovered the horror
Comment from : @istovall2624


@odytrice
I think the extension method conversion approach is better and I prefer it But I don't see anything necessarily wrong with your DTO knowing the about the Domain object brHowever, I think automatically Mapping DTOs to Domain objects is a bad practice in general because there might be business constraints and decisions to be made so that the domain objects are not in the wrong state The forward mapping is fine but the backward mapping should be deliberate and intentional like in a business logic method or subfunction with proper validation and constraints
Comment from : @odytrice


@paulecampbell
what's tl;dw showing in the clip from 0:57 - 1:42?
Comment from : @paulecampbell


@peterjosefsson9857
Thank you and thank you again! I'm a 60yo coder and juniors automapping themselves silly (overposting vulnerabilities, anyone?) just makes me weepbrbrAlso, they write repositories and services that just call each other 1:1 and wouldn't know a business layer if it hit them in the facebrbrAnd yes, there's one repository per table, and the EF context may be injected per request or per service - chaos ensuesbrbrI'm SERIOUSLY thinking about retiring and becoming an open source guru, not having to see other peoples' code
Comment from : @peterjosefsson9857


@nonamezz20
Using extension methods for creating mappers is not a good practice by any means It shows lack of understanding of extension methods
Comment from : @nonamezz20


@MrBildo
Once you realize that the purpose of a domain object is to change state, not represent it, you'll never run into #3 Stop loading domain objects simply to transform them into a dto Use a data transformation layer or better yet, CQRS, and do your data transformation with a lightweight ORM like Dapper Most of the bad use of AutoMapper I see is trying to transform entities into dtos/views
Comment from : @MrBildo


@davidsmartensson
I agree with all of them and personally prefer the extension method as that will catch/automatically update changed property names even without unit test as compile time
Comment from : @davidsmartensson


@xXxRK0xXx
What if the incoming model is a List and you need to map it to a String (separated by some value) In my mind this is mapping, but maybe you see it as business logic?
Comment from : @xXxRK0xXx


@atx1980
I created my own without knowing these solutions 🤦🏼‍♂️ Why do I always do that! Does your course cover this kind of stuff? I love your content
Comment from : @atx1980


@ocnah
Do you have a video about how to do mapping the right way?
Comment from : @ocnah


@benpurcell591
Biggest problem with mappers: using them It's easy to make mistakes and therefore they will need to be unit tested to be sure they work Just write the mapping by hand
Comment from : @benpurcell591


@antonmartyniuk
Completely agree on all the points I have seen all 3 mistakes, mostly 1 and 3rd on few projects I just can stand that mappers can have dependencies The good point in favor of manual mapping is that it's much harder to pass dependencies in the static method rather in the mapping profile
Comment from : @antonmartyniuk


@arjunmenon2901
I have seen people use Newtonsoft serialize and deserialize to do object mapping 😅
Comment from : @arjunmenon2901


@abdelhadyseliem3055
on point 👌
Comment from : @abdelhadyseliem3055


@efimov90
I use something similar like 3rd one I have separate Converter class, which know about both entities and DTOs and i inject in this logger for logging errors when it can't convert one to another It may happens when enums changes and some new values don't know how to convert it to apropriate DTO's value or back if it is possible
Comment from : @efimov90


@poteb
I've done my share of shitty mappings I've learned much the last couple of years about mapping, and I now usually do it without a 3rd party library
Comment from : @poteb


@ehvlullo
Modern programming: manually mapping using an automapper and losing type safety in the process
Comment from : @ehvlullo


@enji_
Have you considered making a zero to hero series for localization? I would love to take that as a course
Comment from : @enji_


@andersborum9267
@nichchapsas, while there are some good ideas and tips in this video, some important aspects aren't entirely true (from a testing perspective)brbrFirst of all, the AccountMappingProfile (for AutoMapper) should obviously be tested seperately; you want to make sure you've got well behaving operators It's an isolated unit and should be tests in isolation, all good herebrbrSecond, the specific strategies (ie specific business logic) implemented in this concrete mapper should be considered implementation details and thus considered entirely irrelevant for consumers (of the IMapper interface) What is being presented here is coupling the system under test (AccountService) to a specific implementation of IMapper, and this approach, when implemented on larger scale, eventually makes it harder to refactor the systembrbrAnd, the major (and perhaps most important) point is that the AccountServiceTest should only verify the behaviour of the its dependencies; it should stay as agnostic to data as possible and stick to verification of the interaction of its dependencies, in this case the IMapperMap() interaction (remember, you don't care about the data, you care about the interaction(s))
Comment from : @andersborum9267


@MoskowGoAwayFromUa
BTW SonarCube has a concern about the last approach with extension It says that you should move that extension should be moved as a method to the result class (if both are located in the same project)
Comment from : @MoskowGoAwayFromUa


@afouadr
For me, implicit operator does the job nicely
Comment from : @afouadr


@T___Brown
The problem is using Automapper The last snippet is the best way imo Automapper does stuffautomatically To me that is worse than the "How does my password get generated"
Comment from : @T___Brown


@cwevers
YES 🙏🙏
Comment from : @cwevers


@Brandon-Shaw
Yeah I've been in a project thats fallen into the "Domain Logic" in the mapper trap Took me ages to rework all that out
Comment from : @Brandon-Shaw


@Jkauppa
if you have a probability of making mistakes (by language design) people will make them, dont use those languages at all
Comment from : @Jkauppa


@PatricSjoeoe
Automapper works very well There are also a validation in Automapper that we using in a unit test to make sure that the develper hasn't map wrong :)
Comment from : @PatricSjoeoe


@IngoBing
After some years I have come to the same conclusion - create a separate static mapper 👍
Comment from : @IngoBing


@charles_kuperus
I prefer the manual mapping method as it is always available and no need to add any NuGet or make any change to any code as it is built in to the language This is the extension mapping method
Comment from : @charles_kuperus



Похожие на The 3 Biggest Mistakes of Object Mapping in .NET видео

Bao giờ có thể rút được kin về ví- achi kiếm tiền online Bao giờ có thể rút được kin về ví- achi kiếm tiền online
РѕС‚ : Achi kiếm tiền online
Download Full Episodes | The Most Watched videos of all time
UGC NET DEC 2023 EXAM ANNOUNCED IN TAMIL ||UGC NET /JRF EXAM UPDATE||UGC NET Dec 2023 Notification UGC NET DEC 2023 EXAM ANNOUNCED IN TAMIL ||UGC NET /JRF EXAM UPDATE||UGC NET Dec 2023 Notification
РѕС‚ : TUITION A PLUS ACADEMY UGC NET paper-1 IN TAMIL
Download Full Episodes | The Most Watched videos of all time
Best book for UGC net paper 1|Best book for UGC NET PAPER 1 | KVS Madaan book for ugc net paper 1 | Best book for UGC net paper 1|Best book for UGC NET PAPER 1 | KVS Madaan book for ugc net paper 1 |
РѕС‚ : मां NETULA NET JRF
Download Full Episodes | The Most Watched videos of all time
NET v/s JRF ? | how to crack NET JRF 2022 | कितने नंबर लाए NET करने के लिए? | by Aditi Mam NET v/s JRF ? | how to crack NET JRF 2022 | कितने नंबर लाए NET करने के लिए? | by Aditi Mam
РѕС‚ : JRFAdda
Download Full Episodes | The Most Watched videos of all time
UGC NET 2023 Best Books? NTA NET Paper 1 Booklist 2023 | UGC NET Dec 2023✍? Shiv Sir Vision JRF UGC NET 2023 Best Books? NTA NET Paper 1 Booklist 2023 | UGC NET Dec 2023✍? Shiv Sir Vision JRF
РѕС‚ : Vision JRFAdda
Download Full Episodes | The Most Watched videos of all time
ASP.NET Community Standup - ASP.NET Architecture Series: AOT in .NET 8 ASP.NET Community Standup - ASP.NET Architecture Series: AOT in .NET 8
РѕС‚ : dotnet
Download Full Episodes | The Most Watched videos of all time
How to Add a Database to Xamarin u0026 .NET MAUI apps with SQLite-net How to Add a Database to Xamarin u0026 .NET MAUI apps with SQLite-net
РѕС‚ : James Montemagno
Download Full Episodes | The Most Watched videos of all time
MEMBANGUN JARINGAN RT RW NET DARI AWAL. (NGOBROL RT RW NET) #PART1 MEMBANGUN JARINGAN RT RW NET DARI AWAL. (NGOBROL RT RW NET) #PART1
РѕС‚ : Fuad Rifai
Download Full Episodes | The Most Watched videos of all time
Net Cup Placement for Hydroponics and DWC- Where to Set Water Level - Net Pot Placement Net Cup Placement for Hydroponics and DWC- Where to Set Water Level - Net Pot Placement
РѕС‚ : JimmyB Harvests
Download Full Episodes | The Most Watched videos of all time
Display ToolTip inside Grid in ASP.Net MVC | ASP.NET CORE Display ToolTip inside Grid in ASP.Net MVC | ASP.NET CORE
РѕС‚ : ASP.NET MVC
Download Full Episodes | The Most Watched videos of all time
 -