❔ ✅ custom mapper and resolvers
Hello, I've been trying to use automapper for a while, but now I've decided to just replace it with my own mapping methods, I've created static extension class, but there is one problem with it. Mapping class is now static, but my resolvers classed need to dependency inject services to work, how I am supposed to call my resolver in static class?
MappingExtensions:
DistanceResolver:
10 Replies
The code calling the MapToPublicAd method can pass in the IDistanceResolver as an arg for it to call, or you'll have to call it outside the func and then pass in the value for the Distance prop
public static PublicAd MapToPublicAd(this Ad ad, User user, IDistanceResolver resolver)
Distance = resolver.Resolve(ad, user)
public static PublicAd MapToPublicAd(this Ad ad, User user, decimal distance)
Distance = distance
I usually pull those parts of maps out of the mapping class and just do them after-the-fact
Let the mapper handle the parts that directly read off of data, and calculated equations to a separate action
but that would mean fill other properties every time after mapping is done
Which is the trade-off you have to decide you would rather deal with, one or the other. Which one is more convenient to you?
I'll probably take IDistanceResolver as a paramether
And I would accept that as a valid solution if it were me
ok, thanks for help 😊
gone wrong
ok so the number of resolvers to send gets unwieldy
it looks funny but it's actually ok
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.