Skip to content
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

Support mapping from a DTO to an object's factory create method #1502

Open
skuirrels opened this issue Sep 21, 2024 · 1 comment
Open

Support mapping from a DTO to an object's factory create method #1502

skuirrels opened this issue Sep 21, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@skuirrels
Copy link

Domain Driven Design is becoming more and more popular and it's common to use a Create Factory method to create objects that have more validation requirements than can be added within just a contractor.

The proposal is to configure the mapping method to specify the factory method needed for object creation, such as in the below:

[Mapper]
public partial class CountryMapper
{
    [MapToFactoryMethod(typeof(Country), nameof(Country.Create))]
    public partial Country MapDtoToCountry(CountryDto dto);
}

Presently this must be performed as below, specifying all fields, which negates the use of a mapper.

[Mapper]
public partial class CountryMapper
{
    public partial Country MapDtoToCountry(CountryDto dto)
    {
        return Country.Create(dto.Code, dto.Name, dto.Continent);
    }
}

Mapster has this feature (albeit using reflection and not source generation) but Mapster is no longer maintained. I feel this is the missing feature to make Mapperly the new defacto standard for dotnet.

@latonz
Copy link
Contributor

latonz commented Sep 26, 2024

This could be implemented but I think a simple property on the ObjectFactoryAttribute should do the job (bool MapToParameters). Feel free to contribute 😉

@latonz latonz added the enhancement New feature or request label Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants