Тёмный
No video :(

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

Nick Chapsas
Подписаться 300 тыс.
Просмотров 113 тыс.
50% 1

Опубликовано:

 

22 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 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.
@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 :)
@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.
@smithcolin00
@smithcolin00 3 года назад
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 3 года назад
100% match properties then use lib blindly then
@zokocx
@zokocx 3 года назад
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.
@IceQub3
@IceQub3 3 года назад
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
@casperhansen826
@casperhansen826 3 года назад
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.
@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.
@kblyr
@kblyr 3 года назад
That code generation feature of mapster is amazing
@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...
@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)
@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.
@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
@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.
@0s0n3gr0
@0s0n3gr0 Год назад
Thanks!
@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.
@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.
@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.
@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
@andresbeltran5779
@andresbeltran5779 Год назад
Great video, nice extension
@KoScosss
@KoScosss 3 года назад
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.
@sasca854
@sasca854 2 года назад
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.
@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.
@user-yb4jd5jv2f
@user-yb4jd5jv2f 3 года назад
Many thanks, for the explanation how mapster working. Thes result of benchmarks is excellent.
@moditrix
@moditrix 2 года назад
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.
@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?
@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.
@soltanalkhatib
@soltanalkhatib 2 года назад
Thanks man, your content is always great.
@markyanthonylaredo2614
@markyanthonylaredo2614 3 года назад
This is interesting .. Thank you so much Nick!
@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.
2 года назад
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 ?
@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.
@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
@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.
@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.
@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.
@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?
@myphonephone8231
@myphonephone8231 3 года назад
Thanks Nick
@MrMatthewLayton
@MrMatthewLayton 3 года назад
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.
@deltaphilip8611
@deltaphilip8611 3 года назад
I liked older versions of Automapper. I feel Mapster will be my next goto.
@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
@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?
@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
@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
@jametime7491
@jametime7491 2 года назад
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
@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.
@Dustyy01
@Dustyy01 2 года назад
At 3:50: Weight = 69m // Yes I am 12 😂😂
@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?
@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)?
@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..
@frankhaugen
@frankhaugen 2 года назад
I use AutoMapper simply because of the error-messages, (I create internal libraries and data integration components)
@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?
@amt-codingbetter2003
@amt-codingbetter2003 2 года назад
I use automapper and I have an automatic mapping susbcription based on an interface
@avinashsanapala165
@avinashsanapala165 3 года назад
Is there any video that shows mapping jsonresponse that comes from api call to a dto c# class
@ralphmaasgmailcom
@ralphmaasgmailcom 3 года назад
Thanks Nick, good video.
@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
@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!
@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?
@adekunlealugbin4120
@adekunlealugbin4120 3 года назад
Wow!!!
@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
@thedarkside0007
@thedarkside0007 3 года назад
i loved agile mapper but once it created huge huge memory leak and i am might test 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
@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? ;-)
@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.
@novids4938
@novids4938 2 года назад
I prefer just using linq projections, for the simpler scenario's.
@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
@dimitryk8429
@dimitryk8429 2 года назад
cool
@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
@jayspduarte
@jayspduarte 3 года назад
Nick, what is this source code editor?
@nickchapsas
@nickchapsas 3 года назад
It’s called Rider and it’s made by JetBrains
@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
@neralem
@neralem 3 года назад
What is mapping?
@beater6967
@beater6967 3 года назад
OMU ValueInjecter
@ahmedifhaam7266
@ahmedifhaam7266 3 месяца назад
Is the project dead now or something?
@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.
@kashqahy6171
@kashqahy6171 Год назад
Map objects manually ... If you are mapping an object twice then write an extension method ... DONE!!! No libraries needed
@kimaji
@kimaji 3 года назад
just a heads up that your video burns my eyes. can we all just embrace the dark theme? we have cookies
@M4pster
@M4pster 2 года назад
Someone call?
@yourpotatoking
@yourpotatoking 3 года назад
καλησπέρα πατριώτη τη μάλες.
@yourpotatoking
@yourpotatoking 3 года назад
για απλίκα το έγραψα μην απάντησης
@IR240474
@IR240474 3 года назад
Whats a MAPPER?
@anatoly-k
@anatoly-k Год назад
what a weird way to get donations by hiding the demo sources 🤨
@user-hk3rf6cw1z
@user-hk3rf6cw1z 2 года назад
#ก
@user-hk3rf6cw1z
@user-hk3rf6cw1z 2 года назад
@ibrahimhussain3248
@ibrahimhussain3248 3 года назад
Wow!!!
Далее
Elegant API Versioning in ASP.NET Core (Web API)
21:27
You are doing .NET logging wrong. Let's fix it
25:29
Просмотров 171 тыс.
What is Span in C# and why you should be using it
15:15
Don't throw exceptions in C#. Do this instead
18:13
Просмотров 256 тыс.
9 "rules" for cleaner code | Object Calisthenics
23:26
Просмотров 117 тыс.
8 await async mistakes that you SHOULD avoid in .NET
21:13
Times Snooker Players Went TOO FAR..
9:22
Просмотров 1,2 млн
3 .NET "Best Practices" I Changed My Mind About
10:16
Просмотров 102 тыс.
The Bingo Paradox: 3× more likely to win
30:15
Просмотров 356 тыс.
Don't Use AutoMapper in C#! Do THIS Instead!
16:17
Просмотров 67 тыс.