No video

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

  Рет қаралды 48,161

Amichai Mantinband

Amichai Mantinband

Күн бұрын

Пікірлер: 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 Жыл бұрын
@@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.
@kmcdo
@kmcdo 2 жыл бұрын
The drought is over, so excited to watch this one!
@yufgyug3735
@yufgyug3735 Жыл бұрын
I want to thank you for this video series, helped me a lot in understanding stuff related to clean architecture.
@amantinband
@amantinband Жыл бұрын
Great to hear!
@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.
@NaveenKumar-hd7mp
@NaveenKumar-hd7mp 2 жыл бұрын
Eagerly waiting for the Episode. Finally 😎
@neutronstar482
@neutronstar482 2 жыл бұрын
I love Mapster much more than any other mapper. Excelent video as allways.
@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
@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 🤙🏼
@LouisWaweru
@LouisWaweru 2 жыл бұрын
Thank you for making these.
@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.
@OzTheWizardOfPorn
@OzTheWizardOfPorn Жыл бұрын
Seven videos in and I have already learned so much
@SibTiger33
@SibTiger33 Жыл бұрын
I've been using mapster for a while (converted from automapper) it really is excellent. Fantastic video 👍🎉🎊
@bennyasaraf7805
@bennyasaraf7805 Жыл бұрын
bro, you killed me at 21:22 lol great walkthru !!! -- thanks
@joaoricardoviccino7311
@joaoricardoviccino7311 2 жыл бұрын
Great, Thanks for the video, I'm loving this knowledge.
@ArielErlijman
@ArielErlijman 2 жыл бұрын
Done! awesome as usual. Waiting for part 8 already!!
@loko-muklisfatoni1665
@loko-muklisfatoni1665 2 жыл бұрын
Finally what I've been waiting for
@ugursesen7629
@ugursesen7629 2 жыл бұрын
I'm looking forward to your videos, great tutorial
@meetingattender8132
@meetingattender8132 2 жыл бұрын
Amazing as always thanks much!!! Keep them coming please.
@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 👍🏼
@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.
@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.
@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
@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 :)
@ryoman76
@ryoman76 2 жыл бұрын
Great! tnk for this series!
@afsanehhazeghi8890
@afsanehhazeghi8890 2 жыл бұрын
Another informative video, thanks many sir
@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.
@nivaldobrasil
@nivaldobrasil Жыл бұрын
Thank you
@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
@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
@DanielTames
@DanielTames 2 жыл бұрын
Thanks! sensei
@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 ?
@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?
@tobiashoft3505
@tobiashoft3505 Жыл бұрын
The tool you use for the project overview screen, what is it called?
@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…
@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
@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 🙂
@torrvic1156
@torrvic1156 6 ай бұрын
Thanks for awesome video! But what about mapping of one collection to another? I fail miserably. How can we do it with Mapster?
@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?
@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 🙂
@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
@turbomen78
@turbomen78 Ай бұрын
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.
@LoZioIAR
@LoZioIAR 2 жыл бұрын
Great!!!
@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 😀
@kennedydre8074
@kennedydre8074 8 ай бұрын
Please what do you se to make your terminal look that cool?
@jodainemoore8300
@jodainemoore8300 9 ай бұрын
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)
@cunzhili2100
@cunzhili2100 Жыл бұрын
The brush tool looks very useful. Could you share the name of the software
@Tof__
@Tof__ 2 жыл бұрын
Is there repository on github for this project? Cannot find it in description. I would appreciate it.
@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.
@Talieization
@Talieization 10 ай бұрын
How did you apply colors in terminal directory path?
@ppenxhchqlz3113
@ppenxhchqlz3113 Жыл бұрын
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?
@kirangrajan
@kirangrajan Жыл бұрын
Hi Everyone, Any idea what is the best approach to test these Mapster mapping configurations using the IMapper interface?
@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.
@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"
@glickyaron9490
@glickyaron9490 Жыл бұрын
Great video, from my experience Mapperly is way better.
@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!!! 🤩🤩🤩
@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);
@LagusAT1
@LagusAT1 Жыл бұрын
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 Жыл бұрын
Problem solved, i have class AuthenticationResponse twice in code, so delete one and mapping working. Happy 3 hours 😅
@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.
@925082
@925082 Жыл бұрын
Mapster giving issue with record no default contractor for type RegisterCommand, Please use ConttructUsing or MapWith
@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" 💪🏼
@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
@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.
@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?
@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.
@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));
@ucretsiztakipci6612
@ucretsiztakipci6612 6 ай бұрын
IgnoreNonMapped is not working damn it.
@timur2887
@timur2887 5 ай бұрын
Сомнительно, но окэй... Стал ли код проще? Нет. Стал ли код эффективнее и быстрее? Нет. Может быть в некоторых случаях будет меньше строк кода, вот и весь профит...
@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(); ?
ASP.NET 8 REST API Tutorial - The "Sweet Spot" Architecture
11:30
Amichai Mantinband
Рет қаралды 17 М.
Running With Bigger And Bigger Feastables
00:17
MrBeast
Рет қаралды 167 МЛН
Dad Makes Daughter Clean Up Spilled Chips #shorts
00:16
Fabiosa Stories
Рет қаралды 3,3 МЛН
OMG what happened??😳 filaretiki family✨ #social
01:00
Filaretiki
Рет қаралды 13 МЛН
Swagger is Going Away in .NET 9!
10:48
Nick Chapsas
Рет қаралды 93 М.
Don't throw exceptions in C#. Do this instead
18:13
Nick Chapsas
Рет қаралды 257 М.
How To Design Amazing REST APIs
18:57
Amichai Mantinband
Рет қаралды 14 М.
The Best Way To Organize Your Program.cs In ASP.NET
6:59
Amichai Mantinband
Рет қаралды 15 М.
Кто убил СССР: называем поименно
54:09
НО.Медиа из России
Рет қаралды 116 М.
Forget Controllers and Minimal APIs in .NET!
14:07
Nick Chapsas
Рет қаралды 66 М.
Running With Bigger And Bigger Feastables
00:17
MrBeast
Рет қаралды 167 МЛН