feat(core): add autoMap mapping configuration #538
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Avoid using the @AutoMap decorator by replacing it with calls to autoMap inside the profile.
Motivation
First of all, great job on
@automapper
! I'm familiar with using the O.G. AutoMapper on C# projects and this library has been a huge help for my "mapping" needs.Nevertheless, I do have some minor pain points with it:
Using the
@AutoMap
decorator on models / DTOs definitions is undesirable, especially when used in DDD(-Lite) projects, where entity definitions are supposed to be "pure", exempt from any mapping responsibilities.Although a good approach for solving the issue above, the
@automapper/classes/transforme-plugin
failed on me on a NestJS project in Monorepo mode; not really sure why. If it's of interest, I'm willing to submit an issue alongside a minimal repository simulating the error.Not only that, neither can be used with constructor assignments:
My homebrewed solution
In the end, I ended up ditching both of the solutions described above and use a local
autoMap
function, which is a simple wrapper overforMember
:Then it can be used as:
Not really sure if it's worthy to be included on the lib. Just thought I would share my issues with it and my approach to working around them.