When we read/write data we need to transport our information from one layer to the next. Our medium of transportation is usually by storing our da...
For further actions, you may consider blocking this person and/or reporting abuse
I had to work on a project that used AutoMapper and I hated it. Yes, it has a lot of features and as you move from similar models and entities to more complex scenarios it has support for most of them, but debugging becomes a nightmare. Here are the issues I have with AutoMapper:
My solution: use dependency injection and inject IMapper when you need mapping. Implement those mappers however you see fit (using, if you must, AutoMapper).
I changed all automapping with this kind of solution in my project and never looked back. It allowed for async mapping, injection of services when I needed extra information (like turning some id into a value or getting details from additional source) and everything was clearly defined in terms of intent and implementation as well as unit testable at every level.
hi Costin. I appreciate you writing this down. I've never faced that much of a problem as you describe above. I think most libraries have a sweet spot where they shine vs don't shine
What’s the advantage of using this instead of implicit operator or explicit operator?
Automapper has more quality of life features like built in mapping validation and helpful errors and it protects you against forgetting to map properties. Also it makes testing your app much easier since it's got the built in DI stuff so you could technically inject a mock mapper.
It's whole purpose is to make your life easier when mapping objects. You should use whatever works best for you.
Thank you for making this question, I am really curious about it too.
I recently found automapper and am really sold on the ease of use and power it offers. It's a really great product.
I am a bit confused about the DI piece though. I don't get why you need to specify the startup class or why it works in that way? I've never seen DI like that. I've kinda gone my own way and created a Singleton I inject on my own instead of using their functionality.
My question is, what is the DI doing with startup class? I can't see a benefit as I still have to define my maps.