❔ Multiple configurations with automapper
I have two automapper configurations, the first one is used to project entities to dtos when querying ef core normally or when just mapping objects, while the second one is for use with OData.
A while back I have asked about conventions of service configuration, and the answer was quite different from my intuitive solution.
So what I'm asking here is what's the conventional way of registering multiple automapper configurations? A factory by name or index does not seem to be officially supported by the public API, should I make a factory myself? Maybe some other library or option exists?
16 Replies
manual mapping is always a solution 🙂
libraries are there to help you, not stand in your way
you can't really use OData with DTOs without automapper
ye you can
source: me :p
it would be a shit ton of boilerplate
and how are you planning to implement expand
generically
oftentimes I prefer a manual
hmm not sure about expand though
this is wrong for many reasons
I've only done select and filters and orderbys
it would still fetch the whole entity from the db even if you need minimal data in the dto
you can't use that for projections
the
.ProjectTo<>(configuration)
has a configuration
parameter. Can you use that to distinguish and use different configurations?you can't remap properties back and forth
yes I can, I can also create a mapper
I'm asking mostly about di here
what's the convention for in fact registering multiple mappers
I'm thinking of just making a factory
I wouldn't be so worried about doing everything through DI
you're not going to mock automapper configurations, right?
no
You could also make multiple interfaces
and then get that interface from DI
yeah I was thinking like a provider that gets you the odata mapper
otherwise IMapper would get the default one
that's kinda logical
still, I'm pretty new to this, and want to learn best practices
I do realize that any single solution is rarely the best at all things
if you make your own "factory"/"provider" that provides the correct IMapper, that's also fine
as long as it's readable code and your team is also ok with it
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.