Тёмный

Object Mapping - Mapster | ASP.NET 6 REST API Following CLEAN ARCHITECTURE & DDD Tutorial | Part 7 

Amichai Mantinband
Подписаться 52 тыс.
Просмотров 49 тыс.
50% 1

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

 

27 окт 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 113   
@olekristiansjbakken4204
@olekristiansjbakken4204 2 года назад
Great series. I love the way he has this internal dialog with Copilot with "YES!" and seems really impressed with it. A bit like a proud dad. I can sometimes hear a smile. Funny :)
@jimhart5797
@jimhart5797 2 года назад
I have a fundamental issue with these mapping libraries. If object mapping is complicated, we run into these weird config statements that are library specific. You will inevitably have to debug some mapping issue that is buried in a library code. In these situations, I would prefer to manually map it. If the mapping is simple, the mapping library doesn't add any real value and I would prefer to manually map it. AutoMapper/Mapster is one of the very vew libraries I do not find a ton of value in. Having said that, this is another outstanding video Amichai. Thank you for this series!!
@amantinband
@amantinband 2 года назад
Thanks, Jim. Mapping libraries aren't for everyone, and it definitely has its cons 🙂
@ppenxhchqlz3113
@ppenxhchqlz3113 2 года назад
@@amantinband Is there a way to map only not default values? Like.. ignore 0's and nulls? Thats a huge problem isnt it? When an object come with some null values and they replace not null values
@krccmsitp2884
@krccmsitp2884 Год назад
There are two sides to everything. When you have some complicated mapping, you should definitely write unit tests for them to be sure the mapping is correct.
@silvertek
@silvertek 2 года назад
Finally! I've been toying around with automapper vs mapster, and this is a great explanation of all that mapster has to offer.
@yufgyug3735
@yufgyug3735 2 года назад
I want to thank you for this video series, helped me a lot in understanding stuff related to clean architecture.
@amantinband
@amantinband 2 года назад
Great to hear!
@DemoBytom
@DemoBytom 2 года назад
Mapping through Mapster/Automapper might be quite volatile. On the early stages of the project we can make sure that if a model needs special mapping, the profile will be added. But after few years, when one model changes it might be very easy to omit/forget to update/provide new mapping profile. This tutorial could really use a glimpse into testing mapping, either through unit tests or integration (?) tests and how to prevent mapping exceptions being discovered at runtime. Especially it could use some good techinques/best practices how to maintain those profiles as the project grows, team members come and go, scopes change etc.
@amantinband
@amantinband 2 года назад
💯. The main issue with mappers (other than the initial learning curve) is runtime exceptions. I edited out the part where I talk about unit tests, but perhaps I should have at least mentioned it in the final version. Unit tests are a must, whether the objects are manually mapped or mapped via some mapper.
@amantinband
@amantinband 2 года назад
We will have an entire section about testing as part of this series. This will include of course examples for testing the various mappings
@mithrilman3421
@mithrilman3421 2 года назад
I was going to say the same, Unit Test is very important, but I see the concern is already addressed and planned on the way
@kmcdo
@kmcdo 2 года назад
The drought is over, so excited to watch this one!
@karolniedziela3658
@karolniedziela3658 2 года назад
I am really grateful for this series. Being used to using Automapper, but i will play around with Mapster. Have to catch with up latest video, and waiting for more.
@brunoweb4
@brunoweb4 2 года назад
Mappings sometimes is really painfull... Thanks for the tips! I'm working in a project and trying to implement validations in the most cleaner way... I hope you talk about it really soon :D
@sushilb7994
@sushilb7994 2 года назад
Yes, we need validation video
@amantinband
@amantinband 2 года назад
Yes, there is a lot to talk about 🤙🏼
@neutronstar482
@neutronstar482 2 года назад
I love Mapster much more than any other mapper. Excelent video as allways.
@LouisWaweru
@LouisWaweru 2 года назад
Thank you for making these.
@NaveenKumar-hd7mp
@NaveenKumar-hd7mp 2 года назад
Eagerly waiting for the Episode. Finally 😎
@ArielErlijman
@ArielErlijman 2 года назад
Done! awesome as usual. Waiting for part 8 already!!
@SibTiger33
@SibTiger33 2 года назад
I've been using mapster for a while (converted from automapper) it really is excellent. Fantastic video 👍🎉🎊
@HaoNguyen-km9xj
@HaoNguyen-km9xj 2 года назад
Waiting for the next part! Will you make videos about the testing unit test, integration test???
@amantinband
@amantinband 2 года назад
Yup 👍🏼
@joaoricardoviccino7311
@joaoricardoviccino7311 2 года назад
Great, Thanks for the video, I'm loving this knowledge.
@Seyanhyriu
@Seyanhyriu 2 года назад
Please, I really need some help! Already lost two days with this issue: I got an inputmodel "OrderRequest" with two attributes: string itemCode, List orders. I'm trying to map it to a list of Order entities and get the same itemCode on all of them. Like this: Controller: _mapper.Map(request); Mapping: config.NewConfig() .Map(dest => dest, src => src.itemCode) .Map(dest => dest, src => src.orders.Adapt()); I get nothing... Empty list. What am I doing wrong? I've tried everything. I'm almost giving up on Mapster. I tried googling it but theres almost nothing about mapster... BTW i'm using mapster to get back a response from an entity and it works. Configurations are working. Thanks a lot for any help!
@Seyanhyriu
@Seyanhyriu 2 года назад
I gave up. Went back to manual mapping :D No more mapster
@canishelix6740
@canishelix6740 2 года назад
Liking the content, when do we get around to DB/Backend storage with this series? Looking forward to Part 8.
@amantinband
@amantinband 2 года назад
Don't worry we'll have multiple videos about EF core after we talk some DDD🙂
@canishelix6740
@canishelix6740 2 года назад
@@amantinband Excellent. Following along with Part 8 now, albeit my own schema and adapting as we go. A more hands-on approach to learning by applying to a project immediately :)
@bennyasaraf7805
@bennyasaraf7805 Год назад
bro, you killed me at 21:22 lol great walkthru !!! -- thanks
@iliyan-kulishev
@iliyan-kulishev 2 года назад
Junior dev here, I'm probably missing something, I can't help it but ask: why do we need a mapping library? Regardless of the types being mapped (DTO, Domain, ViewModel, Request for CQRS handler etc.) each mapping happens in one and only one place in the app. So why is manual mapping considered so hard to do all of a sudden? Or if for some reason the mapping from type A to type B occurs in many places in the code (weird), then why not just implement conversion operator ?
@ugursesen7629
@ugursesen7629 2 года назад
I'm looking forward to your videos, great tutorial
@meetingattender8132
@meetingattender8132 2 года назад
Amazing as always thanks much!!! Keep them coming please.
@loko-muklisfatoni1665
@loko-muklisfatoni1665 2 года назад
Finally what I've been waiting for
@opachshwee5589
@opachshwee5589 2 года назад
Hey man great videos. This series is honestly the best I've seen so far. Any chance you can do some video(s) on proper logging middleware implementation and/or an audit trail with point-in-time rollback capabilities?
@amantinband
@amantinband 2 года назад
Awesome to hear, thanks! I'll definitely touch on logging in future videos
@richardhaughton9633
@richardhaughton9633 2 года назад
Do you recommend injecting the IMapper interface in our mediatr Handlers instead of using the adapt() variant? Is it for testing purposes?
@sushilb7994
@sushilb7994 2 года назад
Very nicely explained. Thank you for yet another useful video.. can you please cover validation in the next video, please?
@amantinband
@amantinband 2 года назад
That's the plan
@diego_samano
@diego_samano 2 года назад
Awesome videos. Keep going this is a fantastic channel.
@bolafahmi
@bolafahmi Год назад
Great series Amichai, btw, I think a better approach for silencing the compiler would be to remove the async keyword at the first place, and in order to return a Task, just return Task.FromResult(any_object_here), this skips the overhead of adding the await/async state machine in IL.
@fieryscorpion
@fieryscorpion 2 года назад
Will you be continuing your DDD video series?
@amantinband
@amantinband 2 года назад
This is still part of the series 🙂 After we get familiar with these libraries and the project structure we will revisit the client application and learn the various DDD concepts while implementing the core logic of the application
@ryoman76
@ryoman76 2 года назад
Great! tnk for this series!
@afsanehhazeghi8890
@afsanehhazeghi8890 2 года назад
Another informative video, thanks many sir
@DeejayWazzouille
@DeejayWazzouille 2 года назад
Hi ! I'm having issue with mapping "id" field, any clue ? It's a long type, dont work with "id", but works with 'Id"
@matheustorresdosreis9508
@matheustorresdosreis9508 2 года назад
Finally! Is it better to use some mapping library or do it manually?
@amantinband
@amantinband 2 года назад
I like this sort of magic. Especially since manual mapping starts nice and clean but becomes quite complex over time. Is it better? Really depends on preference and team
@pilotboba
@pilotboba 2 года назад
I think Mapster also includes C# code generators so the mappings don't need to use reflection. Also, you may consider using code generation to do your Injection rather than assembly scanning as well. Maybe consider an installment on code generation.
@tobiashoft3505
@tobiashoft3505 Год назад
The tool you use for the project overview screen, what is it called?
@microtech2448
@microtech2448 Год назад
Hi, is there option to 1. Ignore certain field while mapping? 2. Skip if souce value is null or default of nullable value type 3. Reverse Map?
@torrvic1156
@torrvic1156 8 месяцев назад
Thanks for awesome video! But what about mapping of one collection to another? I fail miserably. How can we do it with Mapster?
@AlexGait
@AlexGait Год назад
Hey, Amichai! I am using the strongly typed IDs you introduced later (private constructor and public static factory method). In case I wanted to have strongly typed IDs on my Commands and Queries, how would the mapping from GUID to those IDs be configured? config.NewConfig() .Map(dest => dest.UserId, src => UserId.Create(src.UserId)); public record Command(UserId UserId, ...); This doesn't work as Mapster is looking for a constructor for UserId.
@AlexGait
@AlexGait Год назад
I found a solution config.NewConfig() .MapWith(src => UserId.Create(src)); config.NewConfig() .Map(dest => dest.UserId, src => src.UserId) .Map(dest => dest, src => src.Request);
@Marko-the-Beast-Master
@Marko-the-Beast-Master Год назад
Every time I'm trying to make a Request I got error: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1] An unhandled exception has occurred while executing the request. System.ArgumentException: IDX10703: Cannot create a 'Microsoft.IdentityModel.Tokens.SymmetricSecurityKey', key length is zero.
@fasons2
@fasons2 2 года назад
Thank you for your work, it's awesome! I'm curious about mapping in application and infrastructure layers. Shouldn't we use DTOs in application layer to map them to entities in repository? Or is it just redundant work?
@amantinband
@amantinband 2 года назад
The repositories work with domain models. You can, of course, have a mapping layer from domain models to DTOs in your persistence logic. I think it's redundant when using EF Core since we can configure the mapping between the domain models and the actual storage, but we'll talk all about this in future videos 🙂
@larsp5109
@larsp5109 2 года назад
I like explicit Mappings, there was this great addon vsix called MappingGenerator but its creator unfortunately turned it into a paid extension of which the price is a bit steep…
@turbomen78
@turbomen78 3 месяца назад
Hi Amichai there any way to use injected service in each mapping config file that implemnts IRegister? thanks
@SUDHIRKUMAR-kx7gz
@SUDHIRKUMAR-kx7gz 2 года назад
Thanks for one more Awesome Video! Kindly let me know where I can source this on Github if possible.
@davearkley7014
@davearkley7014 Год назад
For DDD I have a private default constructor on my target object with a public static factory method to create the object. Can I force Mapster to use the factory, as currently it throws an exception when it can't find the default constructor. How do you handle this?
@AlexGait
@AlexGait Год назад
It's been a while, but I found a solution. Let's say you want to map a GUID to a UserId with private constructor and public static factory method. config.NewConfig() .MapWith(src => UserId.Create(src)); config.NewConfig() .Map(dest => dest.UserId, src => src.UserId) .Map(dest => dest, src => src.Request);
@MrKlyushin
@MrKlyushin Год назад
@@AlexGait many thx!!! 🤩🤩🤩
@Tof__
@Tof__ 2 года назад
Is there repository on github for this project? Cannot find it in description. I would appreciate it.
@nivaldobrasil
@nivaldobrasil 2 года назад
Thank you
@kennedydre8074
@kennedydre8074 10 месяцев назад
Please what do you se to make your terminal look that cool?
@cunzhili2100
@cunzhili2100 Год назад
The brush tool looks very useful. Could you share the name of the software
@ppenxhchqlz3113
@ppenxhchqlz3113 2 года назад
What if I dont want to map default values? Like if the incoming request have a null value and I dont want to map it?
@SUDHIRKUMAR-kx7gz
@SUDHIRKUMAR-kx7gz 2 года назад
Please anybody help me why i am getting this error "error CS0246: The type or namespace name 'IMapper' could not be found " . I have added below references
@amantinband
@amantinband 2 года назад
Seems right, were you able to fix it?
@DanielTames
@DanielTames 2 года назад
Thanks! sensei
@Talieization
@Talieization Год назад
How did you apply colors in terminal directory path?
@robiulhassan4263
@robiulhassan4263 2 года назад
love your series, but do you have any plan add a logger like serilog? It will be great if you add serilog.
@amantinband
@amantinband 2 года назад
Yup, not sure it'll be as part of this series as it might be too much of a cognitive load, but we'll talk about logging in the future.
@kirangrajan
@kirangrajan Год назад
Hi Everyone, Any idea what is the best approach to test these Mapster mapping configurations using the IMapper interface?
@pedrofreitaslima
@pedrofreitaslima Год назад
I like so much, i don't know this package i always use automapper and i hate it, now i'll use only mapster in my projects
@jodainemoore8300
@jodainemoore8300 11 месяцев назад
I can't get the Mapster to work in the minimal API:InvalidOperationException: Failure to infer one or more parameters. Below is the list of parameters that we found: Parameter | Source --------------------------------------------------------------------------------- request | Body (Inferred) mapper | UNKNOWN mediator | Services (Inferred)
@MilanJovanovicTech
@MilanJovanovicTech 2 года назад
Dynamic mapping with Mapster is my favorite feature. I really dislike the IMapper approach, because it doesn't bring any added value.
@vagnerpadilha3485
@vagnerpadilha3485 2 года назад
can you speak more about this? what do you prefer to user? extension method ".Adapt()" or by dependency injection "IMapper" ? Is there any downside to using the extension method ".Adapt()". the code looks cleaner and more straightforward :D
@amantinband
@amantinband 2 года назад
Well, it depends on your mapping logic. If you have any dependencies, it may be useful to simply mock the mapping. An easy example is something like the following: config.NewConfig() .Map(dest => dest.Name, src => MapContext.Current.GetService().Format(src.Name));
@jerryjeremy4038
@jerryjeremy4038 2 года назад
What's the advantage of using mediator? I used it once and I'm forced to create command classes and other required classes just to make it work.
@amantinband
@amantinband 2 года назад
It's mainly for decoupling layers and splitting logic by feature instead of "service" classes. But as you said, you'll have many more files.
@LoZioIAR
@LoZioIAR 2 года назад
Great!!!
@zhh174
@zhh174 2 года назад
One question how do you see the source code of library in vs code? I knew rider had this feature. But does vs code also have it?
@amantinband
@amantinband 2 года назад
Settings: "omnisharp:Enable Decompilation Support" 💪🏼
@zhh174
@zhh174 2 года назад
Mapster is been my favorite for a while. But it's not actively maintained anymore. Hope it get more attraction so that it gets maintained.
@amantinband
@amantinband 2 года назад
It had some down-time but it's maintained again 🙂
@abhishekbagchi6052
@abhishekbagchi6052 2 года назад
Great video as always One thing i did not understand how you go to the metadata classes of mapster from code?
@iliyan-kulishev
@iliyan-kulishev 2 года назад
Biggest mystery to me too. Watching guys like him and Nick Chapsas doing it makes me feel like a total noob :)
@abhishekbagchi6052
@abhishekbagchi6052 2 года назад
@@iliyan-kulishev well Nick uses jetbrains Rider where that functionality already present.. i.e. downloading external code I am pretty sure its not present in VS Code by default so if you just know what extension Amichai is using we will be able to do it to
@iliyan-kulishev
@iliyan-kulishev 2 года назад
@@abhishekbagchi6052 Well u need to decompile the 3rd party assembly. I've heard about two tools fit for the job: .NET Reflector and dotPeek.
@abhishekbagchi6052
@abhishekbagchi6052 2 года назад
@@iliyan-kulishev yeah but it seems in this video it happened without doing any of that
@amantinband
@amantinband 2 года назад
Haha funny thread 😂 I thought it came from the `ilspy-vscode` extension but I don't have it installed. I honestly don't remember how I configured this and I'm unable to reproduce it on my other machines ATM. Weird. I'll have to dig deeper
@LagusAT1
@LagusAT1 2 года назад
I dont know why, but code on line _mapper.Map(authResult) dont use defined map. Response has set only Token, but other properties are empty. I also try add BeforeMapping, but is not called.
@LagusAT1
@LagusAT1 2 года назад
Problem solved, i have class AuthenticationResponse twice in code, so delete one and mapping working. Happy 3 hours 😅
@bdowns
@bdowns 2 года назад
Very well! How can I ignore null values from ? I'm in troubles 'cause Config .IgnoreNullValues(true) it's ok when ignoring string null values but When my source object have int?, datetime? or decimal? it full overwrite the destinaton values with null.
@bdowns
@bdowns 2 года назад
It's like .IgnoreNullValues(true) just works for string values.
@925082
@925082 Год назад
Mapster giving issue with record no default contractor for type RegisterCommand, Please use ConttructUsing or MapWith
@bobek8030
@bobek8030 2 года назад
When next episodes about ddd?
@amantinband
@amantinband 2 года назад
I think a digestible approach to break down the series is first getting CQRS, MediatR, Mapster, FluentValidation etc' out of the way together with the auth stuff. Then, we can revisit the client application, learn the various DDD concepts while implementing the core logic of the application. What do you think?
@evilTano
@evilTano 2 года назад
@@amantinband yeah, modeling the domain with DDD must have a dedicated video. It's one of the hardest thing to learn.
@glickyaron9490
@glickyaron9490 Год назад
Great video, from my experience Mapperly is way better.
@patrykk.4630
@patrykk.4630 2 года назад
We use AutoMapper for mappings. Sometimes it's hard to find out what is wrong with the code.. This one looks like it's more forgiving. And you said it is faster, will check that out 😀
@timur2887
@timur2887 7 месяцев назад
Сомнительно, но окэй... Стал ли код проще? Нет. Стал ли код эффективнее и быстрее? Нет. Может быть в некоторых случаях будет меньше строк кода, вот и весь профит...
@ucretsiztakipci6612
@ucretsiztakipci6612 8 месяцев назад
IgnoreNonMapped is not working damn it.
@efimov90
@efimov90 2 года назад
Amichai Mantinband, 22:36 is await Task.CompletedTask better than return await ValueTask.FromResult()? Looks like crutch, just for enforce IDE to be silent about this.
@amantinband
@amantinband 2 года назад
Hey Сергей, yes, `await ValueTask.CompletedTask` is a bit more efficient. As you said, this is just to silence the compiler for now
@meetingattender8132
@meetingattender8132 2 года назад
@@amantinband what about: // TODO: remove await Task.Yield(); ?
Далее
Stop Calling Your API a "REST API"
17:42
Просмотров 17 тыс.
Brutally honest advice for new .NET Web Developers
7:19
Don't throw exceptions in C#. Do this instead
18:13
Просмотров 261 тыс.