-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatic DTO mapping #21242
Comments
hi It seems the AutoMapper already has this feature. https://docs.automapper.org/en/stable/Attribute-mapping.html |
Yes, but it requires the contracts layer to reference the domain layer, which is an anti-pattern IMHO. |
I think in this case we can refer to AutoMapper in the Contract module. |
I'm not sure if we are on the same page, but what I meant was, to use AutoMapper's My proposal was to keep the mapping in the application layer (rather than the contracts layer, despite adding an attribute into it), but in an automated manner. This way the contracts layer does not need to reference the domain layer. |
hi ABP has had this feature before. and it decide to remove it that's |
@maliming yes, I'm fully aware of it, but I'm proposing a different approach. I have the feeling that you have missed my point or I was not articulate enough, let me rephrase it: AutoMapper's
|
@hikalkan What do you think? |
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
In ABP we have to create AutoMapper mappings for a domain type and its corresponding DTO type. In multiple projects we developed, we found that most of the time we don't need to configure custom mapping rules for these types, they are basically one-to-one projections. To reduce boilerplate, we developed a method which automatically create these kind of mappings.
Describe the solution you'd like
The idea is to add an attribute
DtoAttribute
:Any DTO class in the application contracts layer could be decorated with this attribute. In the application layer, automatically scan for types with this attribute in the contracts assembly, create mappings accordingly:
mappingDirection
determines the mapping direction, as the enum suggests;SourceTypeName
could be specified or inferred by removing theDto
suffix of the DTO class. The source type is looked up from the domain assembly.We can extend the rules a bit, such as if a type with
[Dto]
has a name ends withInput
, automatically create a DTO-to-source mapping etc., but I'm not sure if it's necessary.Additional context
I'd be happy to submit a PR for this feature.
The text was updated successfully, but these errors were encountered: