Mapster, the best .NET mapper that you are (probably) not using

  Рет қаралды 113,046

Nick Chapsas

Nick Chapsas

Күн бұрын

Become a Patreon and get source code access: / nickchapsas
Check out my courses: dometrain.com
Hello everybody I'm Nick and in this video I wanna talk about a package called Mapster. It's a mapping library that it is packing some really amazing features that I wanted to share with you. No only that but it also performs increadibly well, outperforming all other mappers.
Give Mapster a star: github.com/MapsterMapper/Mapster
Timestamps
Intro and personal take - 0:00
Benchmarks of existing mappers - 1:57
Simple mapping with Mapster - 6:04
Code generation with Mapster - 13:50
Don't forget to comment, like and subscribe :)
Social Media:
Follow me on GitHub: bit.ly/ChapsasGitHub
Follow me on Twitter: bit.ly/ChapsasTwitter
Connect on LinkedIn: bit.ly/ChapsasLinkedIn
#dotnet #csharp #mapster

Пікірлер: 169
@nickchapsas
@nickchapsas 3 жыл бұрын
Which mapper are you using? Do you think there is another mapper with some amazing features that I can try? Leave a comment and let me know EDIT: Mapster also supports code generation without the use of Attributes. I highly recommend checking their great documentation on the matter. If you are interested I can make a deep dive video showcasing it.
@miguelbenitez6311
@miguelbenitez6311 3 жыл бұрын
Autopapper
@SelmanErhanekici
@SelmanErhanekici 3 жыл бұрын
I will be waiting for a deep-dive video showcasing it
@DanteDeRuwe
@DanteDeRuwe 3 жыл бұрын
deep-dive seems interesting! Great vid.
@pilotboba
@pilotboba 3 жыл бұрын
@Sayed Zaman benchmarkdotnet.org/articles/overview.html He has a video on it too.
@reefhound9902
@reefhound9902 3 жыл бұрын
Many years ago I used Automapper but grew tired of slow performance, quirky config, difficult debugging. Manual mapping takes a bit more setup time but I find it faster, easier to understand, easier to debug, and one less package dependency. Based on this video I may have to give Mapster a look see.
@stochastic84
@stochastic84 3 жыл бұрын
I used mapping for a while and stopped. Two deal breakers - 1. Lose the ability to find all usages/references to a property/field using the IDE. 2. Can no longer rename/refactor fields safely without relying on everyone writing comprehensive tests. While tests are great, I never want to have to rely on them for correctness more than necessary (type system is better). They are a safety net, but fallible nonetheless.
@buffdude623
@buffdude623 2 жыл бұрын
This is the biggest thing for me. Losing the ability to find all usages/references to properties.
@igelineau
@igelineau 2 жыл бұрын
which is solved with code generation!
@mabakay
@mabakay 2 жыл бұрын
@@igelineau Which is reinventing the wheel ;-)
@pioners1001
@pioners1001 2 жыл бұрын
@@igelineau The issue with code generation, at least in this example, is that it pollutes your domain model. Domain models should not have references to any infrastructure stuff - mapping in this case (and even worse to a 3rd party library).
@cbrcoder
@cbrcoder 2 жыл бұрын
@@igelineau I think code generation really pollutes your workflow.
@claudiopedalino337
@claudiopedalino337 3 жыл бұрын
What a good video, very well explained and with the benchmark and justifications, thank you very much Nick, I love the content of your channel
@JohnMitchell6
@JohnMitchell6 3 жыл бұрын
Definatly will try in a new home project. Looks great. Great video and explanation. Never come across the benchmarking tool before. Will also play around with that.
@peymannaji
@peymannaji 3 жыл бұрын
Before 24:01 I still wanted to use Automapper and after watching the benchmark result I would say I changed my mind. Really interesting comparison. Thanks Nick!
@DemoBytom
@DemoBytom 3 жыл бұрын
This is veeery interesting indeed! The code generation is sweet! One thing I would be afraid of though, would be that if I add anything to my domain object it will automatically be propagated into the DTO too, which is not something I might want, especially if the domain object is also autogenerated. Scenario: EF Core Database first - we scaffold the context and table model classes with a tool, and generate the .cs files. Then mapper would then just create 1:1 DTOs Usually in situations like this we want to have DTOs defined and map them from domain object, which I see mapster still does better than Automapper. Need to dive deeper into this one :)
@Robert-G
@Robert-G 3 жыл бұрын
Wow, this looks fantastic! Won’t be long before we will have static codegen for a lot of things that required reflection, like DI. nitpick: the code at the end could pass a capacity to the new list, thus not having to double its internal array whenever it was exceeded. This is a very low hanging fruit with sometimes big impact w/o readability downsides. The other thing was doing an index lookup more than once instead of using a local var. But I got the point: It will probably do it it that way automatically...
@possessedllama
@possessedllama 2 жыл бұрын
In your optimisation you could have declared the capacity of the new list since you already knew the source list size, which would have saved the resizing of the internal size of the list.
@kblyr
@kblyr 3 жыл бұрын
That code generation feature of mapster is amazing
@DiomedesDominguez
@DiomedesDominguez 2 жыл бұрын
Thanks for this video, I'm using Automapper since 2013 and all other mapper's implementation (including manual) felt like trying to run in mud. I think I'm going to refactor an old project, after I benchmark some expensive transformation I made in the past.
@markyanthonylaredo2614
@markyanthonylaredo2614 3 жыл бұрын
This is interesting .. Thank you so much Nick!
@andresbeltran5779
@andresbeltran5779 Жыл бұрын
Great video, nice extension
@user-yb4jd5jv2f
@user-yb4jd5jv2f 3 жыл бұрын
Many thanks, for the explanation how mapster working. Thes result of benchmarks is excellent.
@casperhansen826
@casperhansen826 2 жыл бұрын
Mapster without config seems to be the best option, very fast and easy to use. To improve the speed on the manual mapping you should set capacity of the new options list. The advanced mapper that requires attributes on the database object seems very cumbersome.
@soltanalkhatib
@soltanalkhatib Жыл бұрын
Thanks man, your content is always great.
@dbug64
@dbug64 2 жыл бұрын
Very interesting video, thank you Nick. I feel that the point of DTO and translated objects are to have 100% control of how they look, since they might be part of external APIs. So adding a new property to an internal model object should not just appear on the DTOs. How would you best control that while still using Mapster? (Bit lazy now, I could go to the docs of course, but I suspect more in this audience wonders)
@hannasamia6739
@hannasamia6739 3 жыл бұрын
Great Intro, will definitely give it a try. I think it can be a great replacement for Automapper Btw is there a way to get access to the code? it's basically impossible for me to become Patreon since I live in Lebanon and all transactions are blocked.
@biglufik
@biglufik 2 жыл бұрын
Hi, whats the point of having DTOs to be generated ? They will have always the same shape as the source object. If I just want to send the serialized DTO over the wire, I don't see any benefit of the generated code besides the little bit better performance.
@RaMz00z
@RaMz00z Жыл бұрын
Except for very litte simple projects, DTOs have *never* the same shape as the source. DTO will be an aggregate of parts of the system, tailored for the need of that API call. Or you use NoSql and in that case you are right and you don't need another layer.
@IceQub3
@IceQub3 2 жыл бұрын
22:25 If you want even more performance, you should use an array, because you know the size beforehand. Also 'foreach' can actually be faster than 'for' if the iterator is a ref struct, because of array boundary checks. Better than ref struct iterator you must go unsafe, but i think array iterator is ref struct and implemented in unsafe code so it is as fast as it gets. (I may be wrong about array iterator implementation tho)
@IceQub3
@IceQub3 2 жыл бұрын
@@BartKemps there are possibile optimizations, like de-looping if the size is known at JIT time. But iterator optimization and general loops optimization are different depending on the way 'i' is used. In a ref struct iterator, the compiler can loop until pointer is equal to the end of the array, and increment it by sizeof(T) every iteration, so there is no i involved. Every code in dotnet will be optimized a bit differently because the most agressive optimizations happens at JIT time and revolvs the spesific envoriment and runtime huristics
@ralphmaasgmailcom
@ralphmaasgmailcom 3 жыл бұрын
Thanks Nick, good video.
@queenstownswords
@queenstownswords 3 жыл бұрын
Hello Nick, I have never used a mapper before so please give your thoughts on using the mapper to do API contract testing?
@killpopers
@killpopers 3 жыл бұрын
Look good have to take a closer look myself for a new project I'm working I try to avoid double objecting but I think there might be a case for it this will help
@theories1972
@theories1972 2 жыл бұрын
Hi Nick, it is amazing! How it does dependency injection with the code generated mappers as those mappers do not implement an interface? Scan and register all the mappers and get the individual one manually?
@0s0n3gr0
@0s0n3gr0 Жыл бұрын
Thanks!
@glebbsif
@glebbsif 3 жыл бұрын
Good afternoon. How does the library behave with records in .NET 5? I've noticed the tendency that the names of class and record fields should be strictly the same, and also use the same nesting of objects, even though we prescribe a behavior rule. Sometimes this is inconvenient. For example: TypeAdapterConfig.NewConfig() .Map(dest => dest.b, src => src.b) .Map(dest => dest.c, src => src.c) .Map(dest => dest.c.d.e, src => src.c.d.e) .Map(dest => dest.c.d.f, src => src.c.d.f) It just won't work any other way. And another question: what if you work with a model where an entity accepts parameters by constructor but gives them away by the usual get property? Maybe there is some kind of guide to use in new environments? Thank you very much for the answer
@ZlobnyiSerg
@ZlobnyiSerg Жыл бұрын
In your manual mapping code you should initialize List of options with the known collection size to avoid extra memory allocation or copying.
@myphonephone8231
@myphonephone8231 3 жыл бұрын
Thanks Nick
@zokocx
@zokocx 3 жыл бұрын
Mapster is the rael thing. I tryied Automapper few years ago and found it confusing and just adding one more layer which need to be taking care. It make sense for project where there are tons of simple mapping, but I would rather do manual mapping if there are few mappings or mappings are too complex. Plus losing code navigation and static code analysis for me it's big no no. People complaining that if you add additional field in db entity that should not automaticly map, anyway you need to configure that mapping in automapper or any other.
Жыл бұрын
hmm i’m gonna ditch the automapper 🤔 but got a question, do you need to build the project first and then use the generated mapping classes or can it be done (somehow) in the background ?
@KoScosss
@KoScosss 2 жыл бұрын
Why use same dto models as source though? Wouldn’t you want to run code gen once and then edit it as you want? If i understand correctly, every build would rewrite Models folder files with a newly generated code.
@doctorlightman8709
@doctorlightman8709 3 жыл бұрын
Great vid, Nick. Can you share how you made Rider scale that nicely for demoing?
@nickchapsas
@nickchapsas 3 жыл бұрын
I change two settings. One is the IDE font size under the Appearance tab. The second one is the font size under the Color scheme settings.
@deltaphilip8611
@deltaphilip8611 3 жыл бұрын
I liked older versions of Automapper. I feel Mapster will be my next goto.
@MRApht
@MRApht 3 жыл бұрын
Thanks for making the video. Mapster seems extremely useful in the case where you have an entity, maybe generated from JSON, and you want to make a DTO / mapper from it into your businesslogic. I am a little confused about the focus on benchmarks though. In my opinion, mapster is most useful because it actually creates the mapper in C# code for you, which you can then modify and debug through later. New programmers don't have to learn the mapping framework because it is just C#. Has mapping performance ever been important in a project you have worked on?
@nickchapsas
@nickchapsas 3 жыл бұрын
So this is getting a bit deep into how I choose to present a subject when I know the audience. Trying to showcase something in a category and subject that people can have very strong opinions on is really difficult. My approach is to read comments from videos or blogs of people who tackled the same topic and try to address those myself. People have 3 main issues with mappers. Whether there is a reason for them to exist or not, their tendency to be misused and cross responsibility boundaries and their performance compared to manual making and also to each other. This video answers all of them quickly to defuse any charged viewers and then at that point they will happily listen and hopefully learn. It actually shows on the like/dislike ratio. On a personal level yes, I have gotten to a point where removing the mapper increased my application’s RPS by a little but it was literally the last thing left to optimise. I don’t think that they should be considered a performance hit unless you’re really misusing it.
@MrMatthewLayton
@MrMatthewLayton 2 жыл бұрын
What happens when mapping X -> Y requires some sort of resolution via a dependency? i.e. if you wanted to map an identity to a public key, and you require a key management service to do it?
@RaMz00z
@RaMz00z Жыл бұрын
Never do that in a mapper, that is not mapping. Do it beforehand, but not in the mapper itself. Mappers don't have dependencies, ever. It does POCO to POCO and that's it.
@wojciechwilimowski985
@wojciechwilimowski985 2 жыл бұрын
Can I create the DTO myself and just use the code generation to auto generate the mapping (without referencing DTO from the other obj)?
@EMWMIKE
@EMWMIKE 2 жыл бұрын
If you have multiple mappings in different folders, like different apis. Will you end up with one big folder with all mappings or can they be inside each api root folder? Is it possible?
@Vlad-1986
@Vlad-1986 3 жыл бұрын
OK, did it all as you said, but I still don't know how to run my new map in Duke Nukem 3D
@sunnypatel1045
@sunnypatel1045 3 жыл бұрын
Hi Nick I been using automapper for a while now. Does Mapster have something similar method like Ivalueresolver ?
@nickchapsas
@nickchapsas 3 жыл бұрын
Mapster has similar functionality but I think it's called something else using one of the extensions. The problem with IValueResolver in my opinion is that it is hugely misused because it's hiding a lot of the things that the mapper is doing and it's easy to hide some domain logic in there, so I am personally against using them.
@sunnypatel1045
@sunnypatel1045 3 жыл бұрын
@@nickchapsas I only use resolvers as a last resort with complicated mappings. I do agree with your opinion that it does hide business logic. Keep up with the great content I’ll look into mapster!
@soucianceeqdamrashti8175
@soucianceeqdamrashti8175 3 жыл бұрын
Great intro, thanks! One thing I have always wondered is, how do you handle more custom error handling and logging in your mapping if you use mapping frameworks? For instance I would like to throw some custom exception if some field is missing or iterating through a list, log exactly which iteration it failed at.
@nickchapsas
@nickchapsas 3 жыл бұрын
That's isn't logic that belongs in a mapper. The mapper does one job only. Map from one object to the other. If you have a malformed object and can't get map then a validator should throw before it ever gets to the mapper. You also shouldn't log within the mapper. Log after the mapping is done. These questions fall under the "how not to use a mapper" disclaimer that I had in the begining of the video.
@soucianceeqdamrashti8175
@soucianceeqdamrashti8175 3 жыл бұрын
@@nickchapsas , I agree, but one nice aspect of logging the mapping itself is that for instance when using application insights you can use telemetry and follow the mapping as objects are translated. Imagine you are mapping and order object containing a header and several lines and the 5th line is mapped wrong then the telemetry will show that in application insights making it easy to know which line went wrong.
@nickchapsas
@nickchapsas 3 жыл бұрын
It sure is but I would do that externally with a decorator that calls the mapper and not the mapper itself
@soucianceeqdamrashti8175
@soucianceeqdamrashti8175 3 жыл бұрын
@@nickchapsas yes that is a good way around it but won't you have to write a lot of decorators or complicated decorator code if you want to insert logging across your application?
@nickchapsas
@nickchapsas 3 жыл бұрын
@@soucianceeqdamrashti8175 It depends on how you go about it. I've seen it done in so many different ways, from an interface with default implementation, to extension methods on the object class etc. It's too big of a topic to analyse in a youtube comment tbh
@KasperSOlesen
@KasperSOlesen 3 жыл бұрын
Amazing. I have been looking for something like this. I have a couple of former coworkers that have been working on a "not-AutoMapper" extension for Visual Studio based on somewhat the same idea. to generate the mapping code instead of doing it dynamically at runtime. As you have said, its unlikely to be a bottleneck, but at the same time, its also pretty much a free performance and / or time-saving gain without changing much of what you are already doing anyway.
@iivarimokelainen
@iivarimokelainen 3 жыл бұрын
How do you unit test a mapping without basically writing the mapping again but manually?
@RajaKajiev
@RajaKajiev 3 жыл бұрын
A really lazy approach is to serialize then deserialize then compare a bunch of randomly generated objects.
@mabakay
@mabakay 2 жыл бұрын
@@RajaKajiev (☞ ͡° ͜ʖ ͡°)☞
@XXnickles
@XXnickles 3 жыл бұрын
I HATE using mapping generators, as they always adds layers of (unnecessary) complexity, generally impacts performance as they often rely on reflection, hide behavior, and you often find yourself doing customized mapping. Why people consider mappers boilerplate? I have no idea, but I often see this stuff associated with ORM, which may point to something. In any case, mappers are usually simple snippets (even for mappings that relies on multiple objects), and I like the idea of have static compiler checks for them instead of relaying on dynamic maybe-gonna-work-but-can-explode-in-your-face generators.
@avinashsanapala165
@avinashsanapala165 2 жыл бұрын
Is there any video that shows mapping jsonresponse that comes from api call to a dto c# class
@RandallEike
@RandallEike 2 жыл бұрын
You mentioned that there are two groups - those that say mapping should be done manually and those that say dynamically. I'm in a third group that says it should not be done at all. Mapping doesn't make it "safer" rather it only makes it more work to maintain. If you map manually when you update and database models, you need to also need to change the DTO and also the front end anyway. If you map dynamically, you might forget to update the DTO and break the front end. Additionally, your DTO may specify validation for the front end while your database model will specify another set of rules and now you have two potentially conflicting set of rules. But the worst part is the added complexity and overhead of keeping the system up to date. With "Clean Architecture" the Domain model is available to all outer layers, it is best keep the models there as a single source of truth available. I even send these models out of APIs and suppress fields from being serialized via attributes.
@nickchapsas
@nickchapsas 2 жыл бұрын
So how do you make sure that when your domain object is updated you don’t break the API contact?
@RandallEike
@RandallEike 2 жыл бұрын
​@@nickchapsas there are three relevant changes here one could make to a domain object: 1) add a new field, 2) modify a field, 3) remove a field. The first case is a non-breaking change as you can generally add a field to JSON and if the consumer doesn't know about it will ignore. Further, the consumer can now get access the latest new field without having to switch to my latest API! I would include a comment in the documentation noting the field is new so developers won't wonder why they missed it originally. In the second case if the field is named poorly, I'll usually just live if I've already built my database and published my API. Further, the code would smell if I was using a mapper and mapped the new good name to the old bad name. Another option here as well would be use attributes to modify the field names during the JSON serialization, though I like to avoid that as well. The third type of changes is going to be a breaking change to the API because the field (and associated data) is now gone; even a mapper can't help me now. Finally, if there is a case that calls for it, it can be this moment in time that I create a DTO and do the mapping as needed, but there is no reason to create the DTO ahead of time. Finally, I have found that 99% of changes to my domain objects are the first case - adding new fields. I've done many ASP.Net projects for my clients over the last 10 years religiously using AutoMapper and two years ago I finally decided to ban it in my company, ha ha. BTW, love your videos Nick!
@bart.calixto
@bart.calixto 2 жыл бұрын
@@RandallEike this is very interesting. I wonder how do you deal with from "binding" objects (from input) where fields from web that have totally different shape than model. Lists, files, etc. I believe you do manual mapping here?
@RandallEike
@RandallEike 2 жыл бұрын
@@bart.calixto I avoid DTOs where the interface is identical to the database entities. But if I am collecting something from the user (e.g. a file upload Form) different from what is being storing, then I need a DTO. I also might send a DTO to the UI which includes both a DB entity and other fields specifically for the UI. Does that make sense?
@zc2012
@zc2012 3 жыл бұрын
I stand more on group 1 which prefers to write the mapping myself. Objects in different layers are different, auto-mapping might cause incorrect mapping, or even create unexpected values in the objects.
@jametime7491
@jametime7491 Жыл бұрын
Can you please tell me, how can we test mapping with bogus without writing for each property. If I’d done that then I would’ve just did it inside my method to copy from dto to domain object instead, and avoid any mapper altogether
@adekunlealugbin4120
@adekunlealugbin4120 3 жыл бұрын
Wow!!!
@moditrix
@moditrix Жыл бұрын
You can further speed up your own mapping implementation by restricting access by field indexing. You assign product.option [i] to the local variable and then read the individual properties only from the local variable. This avoids access to the index in the array and saves you more precious nanoseconds. It sounds like bullshit, but you can save on it.
@jeremyhb1393
@jeremyhb1393 Жыл бұрын
Hey 🖐, I wanted to share my thoughts on Mapster. While it's a great tool for simple projects, it may not be the best fit for complex projects that involve inheritance hierarchies. One of the main reasons I'm hesitant to use Mapster in these situations is that it doesn't support full mapping of inheritance hierarchies.
@thedarkside0007
@thedarkside0007 3 жыл бұрын
i loved agile mapper but once it created huge huge memory leak and i am might test mapster
@get_ready
@get_ready 3 жыл бұрын
So I just tried it out, it seems interesting, but I can't figure out if we can user generated mappers with instanced imapper. I mean using .Map() method does not seem to invoke generated mapper methods.
@get_ready
@get_ready 3 жыл бұрын
Or do we just directly call adapt(blabla) instead if we go with code gen?
@nickchapsas
@nickchapsas 3 жыл бұрын
Basically your reply
@get_ready
@get_ready 3 жыл бұрын
@@nickchapsas Thanks
@Christobanistan
@Christobanistan Жыл бұрын
I wish there was a mapper lib to explicitly hand EF POCOs mapping, with it's StringLength and data type constraints, which could autoconvert strings (with indication of truncations due to length) and gimme a list of errors for the failed columns instead of just throwing an exception at first failure. Of course I'd need to specify destination properties to ignore and alternate input columns since names could be different. If you guessed I'm converting an SSIS which imports a CSV and then moves the data between various tables, you'd be right! Anyone know of something like that?
@feelingeverfine
@feelingeverfine 3 жыл бұрын
But how would you write your validation and mapping from that generated dto?
@nickchapsas
@nickchapsas 3 жыл бұрын
The mapping is already generated and built into the code. You can use rules using either attributes or use a proper TypeAdapterConfig and use the GenerateMapper extension method. This will instruct the tool to make use of it during generation and bake the logic into the generated mapper. This page contains all the documentation for the tool: github.com/MapsterMapper/Mapster/wiki/Mapster.Tool I think I will make a deep dive video on those features for Mapster
@feelingeverfine
@feelingeverfine 3 жыл бұрын
@@nickchapsas I just don't feel comfortable with attributes in my domain layer. github.com/cezarypiatek/MappingGenerator this is my favorite right now. You can use Rider to generate at design time!!
@nickchapsas
@nickchapsas 3 жыл бұрын
Like I said in my previous comment, you don't have to use attributes. You can use the IRegister approach which doesn't include any attributes at all. I am aware of MappingGenerator but it's not even close to as feature rich as Mapster is so I had to pass. I think it's easier for someone to go from something like Automapper to Mapster rather than stright to MappingGenerator.
@feelingeverfine
@feelingeverfine 3 жыл бұрын
@@nickchapsas sorry didn't read that part. You are correct. The config would be nice. How do the db projections compare to ProjectTo in Automapper in your opinion?
@nickchapsas
@nickchapsas 3 жыл бұрын
@@feelingeverfine I haven't tested it myself yet so I don't an opinion but I did read in their docs that they have the same version called ProjectToType
@jayspduarte
@jayspduarte 3 жыл бұрын
Nick, what is this source code editor?
@nickchapsas
@nickchapsas 3 жыл бұрын
It’s called Rider and it’s made by JetBrains
@kawthooleidevelopers
@kawthooleidevelopers Жыл бұрын
I copied the Mapster setting codes into the project csproj and everything came crashing down. When I remove the codes I can reload the project. I'm scratching my head.
@davidharrington1133
@davidharrington1133 2 жыл бұрын
Use Ctrl + D to duplicate and save using the Clipboard
@sasca854
@sasca854 Жыл бұрын
Idk, seems like this is just introducing additional dependencies for the sake of reallocating work from one area to another at the cost of making your code less intuitive and less predictable. But I guess that is a criticism against using mappers in general rather than Mapster in particular.
@Finezzato
@Finezzato 3 жыл бұрын
Man, this is madness one field to remove or add and you're going into 200 places to change code
@RaMz00z
@RaMz00z Жыл бұрын
This is generated code, you don't modify it manually, ever. Just change in the source and/or destination and rebuild. Basically like a dynamic mapper.
@frankhaugen
@frankhaugen 2 жыл бұрын
I use AutoMapper simply because of the error-messages, (I create internal libraries and data integration components)
@tree267
@tree267 3 жыл бұрын
The code generation is interesting but I’m not decorating my domain objects with Mapster attributes.
@nickchapsas
@nickchapsas 3 жыл бұрын
No need to. You can have all that in you mapper configuration register like the example below and have the same results. You can do everything that attributes can do without attributes using an IRegister config.NewConfig().GenerateMapper(MapType.Map | MapType.MapToTarget);
@tree267
@tree267 3 жыл бұрын
@@nickchapsas Fair enough then, still it’s going to take a lot to get me to migrate hundreds of automapper mappings!
@nickchapsas
@nickchapsas 3 жыл бұрын
@@tree267 Oh yeah totally, I mean you wouldn't migrate if you already have up and running to use a different mapper. It's way too big of a risk to consider. It's more for new projects for me.
@ivcbusinesssystems6613
@ivcbusinesssystems6613 3 жыл бұрын
@@tree267 From what you've seen, is this easier/simpler than automapper or about the same?
@shayvt
@shayvt 3 жыл бұрын
Are you using jb Rider on linux?
@nickchapsas
@nickchapsas 3 жыл бұрын
The video is recorded on Windows but I am using Rider on my Linux laptop yeah
@shayvt
@shayvt 3 жыл бұрын
@@nickchapsas I think you should make a video on your dev environment :) I'm trying now to move my dev laptop to linux. I installed kubuntu and want to give it a try. Currently working on windows 10, but with the release of .net core, windows become less and less needed.
@hazlotumismo1419
@hazlotumismo1419 2 жыл бұрын
I'm calling a basic get method from a BFF to a Microservice wihtin a Parallel.ForEachAsync and somethimes I'm receiving this error: {"code":"RuntimeError","message":"TypeAdapter.Adapt was already called, please clone or create new TypeAdapterConfig.","source":"Mapster","details":{},"innerError":null} Can someone help me please?
@amt-codingbetter2003
@amt-codingbetter2003 2 жыл бұрын
I use automapper and I have an automatic mapping susbcription based on an interface
@smithcolin00
@smithcolin00 2 жыл бұрын
For any newbies in here, I'd suggest skipping the mapping libraries entirely. They aren't necessary and they hide important code. Instead, write the mapping code manually where it's needed. If you start to duplicate mapping code, pull it into a separate shared class. It's that simple. You don't need a library :)
@trongphan6197
@trongphan6197 2 жыл бұрын
100% match properties then use lib blindly then
@zokocx
@zokocx 2 жыл бұрын
this kind of mapping libs are for lazy programmers, programmers are lazy, mapping domain obj let say applicaiton obj is dull and repetitive and programmers like automating things so they can focus on interesting problemes
@douglasbeck4625
@douglasbeck4625 2 жыл бұрын
Your advice is proper for POC and Demo products but is horrible for production code. Mapping helps decouples your layers which is a major part of SOLID practices. I have yet to see a project that is maintainable not following these best practices. There is a ceiling and a complete rewrites almost always leads to failure and cost/timeline overruns if you could convince the business to allow it.
@Rexxior
@Rexxior 2 жыл бұрын
I agree, you don't need a mapping libraries. DTO should only contain what the client needs, nothing more, nothing less. Never map everything from domains straight to DTOs. I usually manually specify all properties in the DTOs according to business requirements. My mapping has two parts: 1. use reflection to map the properties with exact same name and type automatically and ignore all navigation properties. 2. manually handle the rest of the dto properties, with business logics as required(no dependencies). Mapping from DTO to Domain follows the same principle, use reflection for some identical properties and manually map the rest. Using any auto-mapper libs to map exactly what the client needs would require the same steps: 1. automapping some properties(similar as using reflection); 2. write mapping configuration(same as manual mapping). But with tons of extra complexity.
@mabakay
@mabakay 2 жыл бұрын
@@douglasbeck4625 He did not write to make the presentation layer use a domain object.
@dimitryk8429
@dimitryk8429 2 жыл бұрын
cool
@Dustyy01
@Dustyy01 2 жыл бұрын
At 3:50: Weight = 69m // Yes I am 12 😂😂
@novids4938
@novids4938 Жыл бұрын
I prefer just using linq projections, for the simpler scenario's.
@neralem
@neralem 3 жыл бұрын
What is mapping?
@AngusMcIntyre
@AngusMcIntyre 3 жыл бұрын
I'll consider it when it uses source generators. Domain should have no knowledge of your presentation objects. Not a big fan of polluting my domain classes with attributes either.
@Finezzato
@Finezzato 3 жыл бұрын
like he said you don't have to use attributes
@nordern1
@nordern1 3 жыл бұрын
Writing manual mappers buries your interesting code in boilerplate. If I see an express mapper with a .Member config I can immediately see what the interesting part of the mapping is. In a manual mapping, it is surrounded by pure noise. Oh, you are assigning a.field to b.field? Never would have guessed. Why are you telling me this?
@mabakay
@mabakay 2 жыл бұрын
Better to hide everything to a.MapTo(b) and pray that this will work as the project evolves, names and types change ;-)
@nordern1
@nordern1 2 жыл бұрын
@@mabakay You have to pray that you don't accidentally create two types that get mapped to each other with the same field name and type but incompatible semantics? If that's the level of defensive coding you're working with I'd hate to see that code. Also, manual code would in that scenario fail you in the exact same way.
@beater6967
@beater6967 3 жыл бұрын
OMU ValueInjecter
@vinniehsu7092
@vinniehsu7092 3 жыл бұрын
OneOf was mentioned in the description which might be a mistake due to copy and paste... Still a nice introduction to Mapster anyway.
@nickchapsas
@nickchapsas 3 жыл бұрын
I should stop editing videos late at night :D Thanks for pointing it out
@yourpotatoking
@yourpotatoking 3 жыл бұрын
καλησπέρα πατριώτη τη μάλες.
@yourpotatoking
@yourpotatoking 3 жыл бұрын
για απλίκα το έγραψα μην απάντησης
@lukeno4143
@lukeno4143 3 жыл бұрын
What is mapping? ive never heard of it and you didnt really explain why you would be doing it?
@nickchapsas
@nickchapsas 3 жыл бұрын
It is the idea of splitting your C# classes to different objects that are used in different players of your application. It can be done for multiple reasons such as dto or api versioning and the ability to add thing like validation in objects that are used in the domain layer
@hassejansson
@hassejansson 3 жыл бұрын
so, why did you watch it, if you dont know whats the purpose of mapping?
@mabakay
@mabakay 2 жыл бұрын
@@hassejansson We could turn the question around. If you know what mapping is and can do it well, why did you watch? ;-)
@mortenbork6249
@mortenbork6249 2 жыл бұрын
I do not understand why mappers are so popular, set up properties as an interface, and there you go. You have the same option as the mappers, you barely have boilerplate code, and they are much easier to unit test, normally. Mappers are code smell. Frameworks usually do not want you to move away from them, so they don't like to make that process easy, meaning that if you do wish to change your mapper framework, you have to rewrite a lot of code. While if you simply did interface based mapping, you .... don't.
@RaMz00z
@RaMz00z Жыл бұрын
So you like to clutter your domain oobjects with dozens of interfaces (not defining behavior btw, talk about code smell...), that belong to the API side of the system ? Yeah, no. And as to frameworks, just abstract it if you're afraid, that's a non issue..
@ronnyek4242
@ronnyek4242 2 жыл бұрын
I really hate that there is a need for mappers in the firstplace
@nickchapsas
@nickchapsas 2 жыл бұрын
Not much we can do about that
@JinnGuild
@JinnGuild 2 жыл бұрын
Losing me with the attributes as I watch this. If my models and/or data entities are in different projects, but my DTO is controlled and tested in my Domain, I'd rather have some FluentAPI or configuration or something to apply those attributes instead of taking a dependency in my `Core` projects.
@nickchapsas
@nickchapsas 2 жыл бұрын
There is a fluent api and configuration to apply those attributes instead of having them as attributes in the DTO
@JinnGuild
@JinnGuild 2 жыл бұрын
@@nickchapsas First... epic for you to reply to an old vid comment. :). Second, that is a great bit of detail which may push me over the edge to give it chance. So thank you for taking the time to throw that out there.
@kimaji
@kimaji 3 жыл бұрын
just a heads up that your video burns my eyes. can we all just embrace the dark theme? we have cookies
@ahmedifhaam7266
@ahmedifhaam7266 22 күн бұрын
Is the project dead now or something?
@IR240474
@IR240474 3 жыл бұрын
Whats a MAPPER?
@M4pster
@M4pster 2 жыл бұрын
Someone call?
@mohammadmahditalachi9211
@mohammadmahditalachi9211 3 жыл бұрын
I have just benchmarked both packages ProjectTo method Auto mapper performance is great auto mapper : 250us Mapster : 485us Interesting...
@nickchapsas
@nickchapsas 3 жыл бұрын
I can't have an opinion on those results since I don't have access to your benchmarking code but yeah as demonstrated on the video both mappers are very performant
@user-hk3rf6cw1z
@user-hk3rf6cw1z 2 жыл бұрын
#ก
@user-hk3rf6cw1z
@user-hk3rf6cw1z 2 жыл бұрын
@kashqahy6171
@kashqahy6171 Жыл бұрын
Map objects manually ... If you are mapping an object twice then write an extension method ... DONE!!! No libraries needed
@anatoly-k
@anatoly-k Жыл бұрын
what a weird way to get donations by hiding the demo sources 🤨
@ibrahimhussain3248
@ibrahimhussain3248 3 жыл бұрын
Wow!!!
Elegant API Versioning in ASP.NET Core (Web API)
21:27
Nick Chapsas
Рет қаралды 94 М.
You are doing .NET logging wrong. Let's fix it
25:29
Nick Chapsas
Рет қаралды 168 М.
КАРМАНЧИК 2 СЕЗОН 6 СЕРИЯ
21:57
Inter Production
Рет қаралды 442 М.
Cat story: from hate to love! 😻 #cat #cute #kitten
00:40
Stocat
Рет қаралды 14 МЛН
Cute Barbie Gadget 🥰 #gadgets
01:00
FLIP FLOP Hacks
Рет қаралды 26 МЛН
CAN YOU HELP ME? (ROAD TO 100 MLN!) #shorts
00:26
PANDA BOI
Рет қаралды 36 МЛН
Where are types allocated in .NET and why people get it so wrong
14:35
Mapster. Автоматизация сопоставления типов
23:50
Архитектор ПО. Александр Желнин
Рет қаралды 4,3 М.
3 .NET "Best Practices" I Changed My Mind About
10:16
Nick Chapsas
Рет қаралды 99 М.
Don't throw exceptions in C#. Do this instead
18:13
Nick Chapsas
Рет қаралды 248 М.
The 3 Biggest Mistakes of Object Mapping in .NET
11:33
Nick Chapsas
Рет қаралды 63 М.
What is Span in C# and why you should be using it
15:15
Nick Chapsas
Рет қаралды 247 М.
What's New in C# 12 | .NET Conf 2023
35:28
dotnet
Рет қаралды 53 М.
The New .NET 9 HybridCache That You Must Upgrade To!
14:34
Nick Chapsas
Рет қаралды 38 М.
КАРМАНЧИК 2 СЕЗОН 6 СЕРИЯ
21:57
Inter Production
Рет қаралды 442 М.